有人向我指出 bluebird 中的 Promise.bind()
以便能够在 promise 链中拥有上下文。
但是,当我仅引用 Promise 对象(带有 then
和 catch
API 的对象时,我的用例要求我“从外部”使用此上下文)。
这可能吗?
最佳答案
当然,.bind
有一个非静态对应项。
yourPromise.bind({x:3}).then(function(data){
console.log("yourPromise fulfilled with", data, "and x is ", this.x);
});
关于promise - Bluebird,Promise.bind - 如何访问待定 promise 中的绑定(bind)上下文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24333214/