JS Promises:then() 方法总是 return 一个 promise,还是 return 一个 thenable?
JS Promises: does the then() method always return a promise, or can it return a thenable?
我正在阅读 this article 关于 Promise 链的内容,上面写着“a handler may return not exactly a promise, but a so-called “thenable” object
”。我想知道以下哪项是正确的:
1) 处理程序可以 return promise 或 then-able 对象,但包含处理程序的 then()
方法必须 return promise。
2) 处理程序可以 return promise 或 then-able 对象,包含处理程序的 then()
方法也可以 return promise 或 then-able对象。
它不是 promise unless its .then(…)
method returns a promise,如果它是 ES6 原生的 Promise
那么它肯定会。
一个thenable'sthen
方法可以return任何东西(包括undefined
)。
我正在阅读 this article 关于 Promise 链的内容,上面写着“a handler may return not exactly a promise, but a so-called “thenable” object
”。我想知道以下哪项是正确的:
1) 处理程序可以 return promise 或 then-able 对象,但包含处理程序的 then()
方法必须 return promise。
2) 处理程序可以 return promise 或 then-able 对象,包含处理程序的 then()
方法也可以 return promise 或 then-able对象。
它不是 promise unless its .then(…)
method returns a promise,如果它是 ES6 原生的 Promise
那么它肯定会。
一个thenable'sthen
方法可以return任何东西(包括undefined
)。