Replies: 1 comment
-
This is sort of mentioned by:
The |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Consider the following code:
This throws an error because
Promise.resolve
is being called incorrectly—it expectsthis
to refer to thePromise
constructor, but insidemap
, if we write the code as shown above,this
becomes the global/window object orundefined
(in strict mode).When we use
values.map(Promise.resolve)
,Promise.resolve
is passed as a function reference, not as a method call on thePromise
object. In JavaScript, methods lose theirthis
binding when passed as callbacks.Promise.resolve
is designed to be called with thePromise
constructor as itsthis
context. When it's passed as a standalone function, it loses itsthis
context (thePromise
constructor), causing the internal PromiseResolve operation to attempt execution onundefined
or the global/window object instead of on thePromise
constructor.However, I can't find any documentation about this "PromiseResolve called on non-object" TypeError. Could anyone point me to any existing documentation on this? If none exists, I'd be happy to create some. 😄
related docs:
reference links:
Beta Was this translation helpful? Give feedback.
All reactions