bluebird
2014-09-17 本文已影响0人
sshmyeclipse
Core
new Promise(Function<Function resolve, Function reject> resolver) -> Promise
创建一个新的Promise。传入的function将会接收两个functions:resolve和reject作为它的参数,这可以称为封装的promise.
例如:
function ajaxGetAsync(url) {
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest;
xhr.addEventListener("error", reject);
xhr.addEventListener("load", resolve);
xhr.open("GET", url);
xhr.send(null);
});
}