码迷,mamicode.com
首页 > 其他好文 > 详细

promise

时间:2015-06-08 00:49:25      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:

var workAsync = function() {
    var p = new Promise(function(resolve, rej) {
        $.get("http://....", function(rs){
            resolve("dddddddd");
        })
    });
    return p;
}

workAsync().then(function(data) {
    console.log(data);
});

 

var p1 = Promise.resolve(3);
var p2 = Promise.resolve(999);
Promise.all([p1, p2]).then(function(values) {
    console.log(values); // [3, 999]
});

 

var workAsync = function(url) {
    var p = new Promise(function(resolve, rej) {
        $.get(url, function(rs){
            resolve("dddddddd");
        })
    });
    return p;
}

var tasks = [];
tasks.push(workAsync("http://1...."));
tasks.push(workAsync("http://2...."));

Promise.all(tasks).then(function(values) {
    console.log(values); // [...]
});

 

promise

标签:

原文地址:http://www.cnblogs.com/eturn/p/4559651.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!