原文:http://liubin.org/promises-book/#ch2-promise.then 从代码上乍一看,aPromise.then(...).catch(...)像是针对最初的aPr
原文:http://liubin.org/promises-book/#ch2-promise.then
从代码上乍一看, aPromise.then(...).catch(...)
像是针对最初的 aPromise
对象进行了一连串的方法链调用。
然而实际上不管是 then
还是 catch
方法调用,都返回了一个新的promise对象。
下面我们就来看看如何确认这两个方法返回的到底是不是新的promise对象。
var aPromise = new Promise(function (resolve) { resolve(100);});var thenPromise = aPromise.then(function (value) { console.log(value);});var catchPromise = thenPromise.catch(function (error) { console.error(error);});console.log(aPromise !== thenPromise); // => trueconsole.log(thenPromise !== catchPromise);// => true