javascript - What does this statement means: "all = Promise.all.bind (Promise)"? -
i know bind bind methods object being passed. but, not understanding here that, why passing class name bind?
one answer got expert was, "this make function 'independent'" again, didn't understand. might stupid not understand , go mad on 1 statement, but, please explain this?
it's not "class name," it's object. (specifically, function; functions objects in javascript. more specifically, constructor function.)
promise.all(...) looks all property on promise object , calls all this set promise. all(...), need bind function this promise when call different way. that's all = promise.all.bind(promise) does.
if did all = promise.all, when called all(...), this during call not refer promise (it global object in loose mode or undefined in strict mode). all relies on this referring constructor function promises (promise, instance).
i know
bindbind methods object being passed
let's put different way: a = b.bind(c) returns new function (a) that, when called, call b ensuring this set c during call. result called bound function, because this value bound it.
see also:
Comments
Post a Comment