有人指着我在蓝鸟中Promise.bind()
能够在承诺链中拥有一个上下文。
但是,我的用例要求我使用此上下文"来自外部"当我只引用promise对象(带有then
和catch
API的对象)时。
这可能吗?
答案 0 :(得分:4)
当然,.bind
有一个非静态对应物。
yourPromise.bind({x:3}).then(function(data){
console.log("yourPromise fulfilled with", data, "and x is ", this.x);
});