So I was taking a look at this thread discussing retrying promises and I was curious as to how and why bind was used in this particular piece of code. This piece of code was used a helper function by a poster to delay and retry promises that were rejected.
var t = 500;
function rejectDelay(reason) {
return new Promise(function(resolve, reject) {
setTimeout(reject.bind(null, reason), t);
});
}
As I understand it, bind is used to redefine the scope. When you bind to null, you bind to global scope, but what is the reason for binding the rejection of a promise globally? Essentially, why does the scope of the reject portion of handling a promise matter? Thank you for your help.