How do I convert an existing callback API to promises?
问题 I want to work with promises but I have a callback API in a format like: 1. DOM load or other one time event: window.onload; // set to callback ... window.onload = function() { }; 2. Plain callback: function request(onChangeHandler) { ... } request(function() { // change happened ... }); 3. Node style callback ("nodeback"): function getStuff(dat, callback) { ... } getStuff("dataParam", function(err, data) { ... }) 4. A whole library with node style callbacks: API; API.one(function(err, data)