美文网首页
js.Promise 传值

js.Promise 传值

作者: 许道龙 | 来源:发表于2016-07-15 09:49 被阅读0次
function doubleUp(value) {
    return value * 2;
}
function increment(value) {
    return value + 1;
}
function output(value) {
    console.log(value);// => (1 + 1) * 2
}

var promise = Promise.resolve(1);
promise
    .then(increment)
    .then(doubleUp)
    .then(output)
    .catch(function(error){
        // promise chain中出现异常的时候会被调用
        console.error(error);
    });

相关文章

网友评论

      本文标题:js.Promise 传值

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