我想使用promises,但我有一个回调API,格式如下:
window.onload; // set to callback
...
window.onload = function() {
};
Run Code Online (Sandbox Code Playgroud)
function request(onChangeHandler) {
...
}
request(function() {
// change happened
...
});
Run Code Online (Sandbox Code Playgroud)
function getStuff(dat, callback) {
...
}
getStuff("dataParam", function(err, data) {
...
})
Run Code Online (Sandbox Code Playgroud)
API;
API.one(function(err, data) {
API.two(function(err, data2) {
API.three(function(err, data3) {
...
});
});
});
Run Code Online (Sandbox Code Playgroud)
我有一个简单的代码,除了Internet Explorer 11之外,在每个浏览器上运行都很完美.如何让它在所有浏览器上运行?
提前致谢.
'use strict';
let promise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("result");
}, 1000);
});
promise
.then(
result => {
alert("Fulfilled: " + result);
},
error => {
alert("Rejected: " + error);
}
);
Run Code Online (Sandbox Code Playgroud)