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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Consider the following code:
This throws an error because
Promise.resolveis being called incorrectly—it expectsthisto refer to thePromiseconstructor, but insidemap, if we write the code as shown above,thisbecomes the global/window object orundefined(in strict mode).When we use
values.map(Promise.resolve),Promise.resolveis passed as a function reference, not as a method call on thePromiseobject. In JavaScript, methods lose theirthisbinding when passed as callbacks.Promise.resolveis designed to be called with thePromiseconstructor as itsthiscontext. When it's passed as a standalone function, it loses itsthiscontext (thePromiseconstructor), causing the internal PromiseResolve operation to attempt execution onundefinedor the global/window object instead of on thePromiseconstructor.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