Tag: jquery deferred

Q.defer()和Promise()之间的区别

我试图理解为什么下面的代码与Q.defer()和Promise() 情况1 :当我使用Q.defer() getDocument(id) .then(function (response) { console.log('in first then') return 'from two'; }).then(function (response) { console.log(response) }); var getDocument=function(){ var b = Q.defer(); b.resolve('from getDocument'); // here will do some async operation..this is just an example return b.promise; } 输出: in first then undefined 案例2 :使用Promise() getDocument(id) .then(function (response) { console.log('in first then') return […]