首页 > 其他 > 详细

promise捕获错误

时间:2014-09-18 14:40:34      阅读:253      评论:0      收藏:0      [点我收藏+]
function fn(){
            var a = $.Deferred();
            a.reject(‘hahaha精神工疾‘);
            return a.promise();
        }

        fn().then(function() {
            console.log(‘success 1‘);
        },function (msg) {
            console.log(msg);
        }).then(function() {
            console.log(‘success 2‘);
        },function (msg) {
            console.log(msg);
        });
//‘hahaha精神工疾’
//underfined

then的错误执行会传递,但错误信息不传递

then支持延续任务调用方式(Continuation tasks),而done不支持
比如then可以这样用,而done不可以:
promise().then().then().then() 

 

promise捕获错误

原文:http://www.cnblogs.com/cjy1993/p/3979103.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!