promise - Bluebird,Promise.bind - 如何访问待定 promise 中的绑定(bind)上下文?

标签 promise bluebird

有人向我指出 bluebird 中的 Promise.bind() 以便能够在 promise 链中拥有上下文。

但是,当我仅引用 Promise 对象(带有 thencatch API 的对象时,我的用例要求我“从外部”使用此上下文)。

这可能吗?

最佳答案

当然,.bind 有一个非静态对应项。

yourPromise.bind({x:3}).then(function(data){
     console.log("yourPromise fulfilled with", data, "and x is ", this.x);
});

这是一个fiddle illustrating the usage .

关于promise - Bluebird,Promise.bind - 如何访问待定 promise 中的绑定(bind)上下文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24333214/

相关文章:

c++11 - 带有自定义分配器的 std::promise 似乎使用 global new

javascript - React - 控制对服务器的 AJAX 调用

javascript - 调试未处理的 Promise 拒绝

javascript - 如何将现有的回调 API 转换为 Promise?

javascript - Node 返回 BluebirdJS Promise

javascript - 如何在nodejs中实现bluebird promise

javascript - 等待所有响应,然后调用函数

javascript - 之前和之后的捕获位置

javascript - 将参数传递给生成器函数

第二次运行时 Payload() 的 Node.js 'Object is not a function'