bluebird

作者: sshmyeclipse | 来源:发表于2014-09-17 14:41 被阅读0次

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);

});

}

相关文章

网友评论

      本文标题:bluebird

      本文链接:https://www.haomeiwen.com/subject/xncutttx.html