It's not a "class name," it's an object. (Specifically, a function; functions are objects in JavaScript. Even more specifically, a constructor function.)
Promise.all(...)
looks up the all
property on the Promise
object and calls all
with this
set to Promise
. So to do that with just all(...)
, we need to bind the function so that this
is always Promise
even when we call it a different way. That's what all = Promise.all.bind(Promise)
does.
If we just did all = Promise.all
, then when we called all(...)
, this
during the call would not refer to Promise
(it would be the global object in loose mode or undefined
in strict mode). all
relies on this
referring to a constructor function for promises (Promise
, for instance).
I know that bind
will bind methods this to the object being passed
Let's put that a different way: a = b.bind(c)
returns a new function (a
) that, when called, will call b
ensuring that this
is set to c
during the call. The result is called a bound function, because its this
value is bound to it.
See also: