Today I found out that Deferred.then(null,func) and Deferred.fail(func) not the same in jQuery. In the ES6 promise, Promise.then(null,func) and Promise.catch(func) are the same thing, so I was confused by the jQuery functions.
The only difference I know of is:
$.Deferred().reject().promise() .fail(function(){ return $.Deferred().resolve().promise(); }) .then(function(){ console.log('fail caught error'); // NOT printed }); $.Deferred().reject().promise() .then(null,function(){ return $.Deferred().resolve().promise(); }) .then(function(){ console.log('then caught error'); //printed });
Are there any other useful differences?
source share