Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
191
rated 0 times [  198] [ 7]  / answers: 1 / hits: 38012  / 11 Years ago, wed, may 8, 2013, 12:00:00

I have some code like:



var bar = foo().then(function success(value) {
// compute something from a value...
}, function failure(reason) {
// handle an error...
});


How do I bind the failure function to the this object in the context of bar. I know I will have to use myFunc.bind(this) but what do I substitute in place of myFunc?


More From » promise

 Answers
17

You can use bind like this:



var bar = foo().then(function success(value) {
// compute something from a value...
}, function failure(reason) {
// handle an error...
}.bind(this));

[#78360] Tuesday, May 7, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
magdalena

Total Points: 364
Total Questions: 101
Total Answers: 92

Location: Namibia
Member since Mon, Nov 14, 2022
2 Years ago
magdalena questions
Thu, May 12, 22, 00:00, 2 Years ago
Fri, Jun 18, 21, 00:00, 3 Years ago
Fri, Mar 26, 21, 00:00, 3 Years ago
Thu, Oct 29, 20, 00:00, 4 Years ago
;