-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent propagation of promise.bind() #738
Comments
Interesting, thanks. However I'd argue that the first is correct behaviour and the propagation of the bound value is the bug. Promise.bind(a).then(function() {
return Promise.bind(b);
}).then(function() {
console.log(this); // a or b?
}) Especially when some of your handlers are returning promises that you didn't create yourself, you'll want it to be |
@bergus it should be |
@benjamingr Yes, but the case that "works" for the OP is a bug, isn't it?
Especially that it works when |
Reopening because either the first behaviour is a bug, or the second one is 😄 |
@bergus Yes, I agree. But propagating function wrappedApi(args) {
var _resolve;
var _reject;
var promise = new Promise(function(resolve, reject) {
_resolve = resolve;
_reject = reject;
});
return prerequisite().then(function() {
return ajax(args).then(function(val) {
_resolve(this);
return val;
}, function(e) {
_resolve(this);
throw e;
});
}, function(e) {
_reject(e);
throw e;
}).bind(promise);
}
wrappedApi({ foo: 1 }).then(function(result) {
console.log(this.responseText);
}); If there is a method to propagate function wrappedApi(args) {
return prerequisite().then(function() {
return ajax(args).propagateContext();
});
} |
The intention has never been so that unknown code could change |
@petkaantonov The result is not the XHR object. How to resolve the promise with |
I don't think you should do that at all. If |
@bergus If prerequisite fails, you can handle it inside Returning |
Outputs
window
.However appending a then() makes it work:
The text was updated successfully, but these errors were encountered: