0

If I try in Google Chrome's dev tool:

fn = async () => {
  await new Promise((res) => setTimeout(res, 3000));
  return 123;
};

fn.constructor           // => ƒ AsyncFunction() { [native code] }

fn.__proto__.__proto__ === Function.prototype           // => true

AsyncFunction            // => Uncaught ReferenceError: AsyncFunction is not defined

From the above, it seems fn is an AsyncFunction instance, and AsyncFunction "is-a" Function, but AsyncFunction doesn't exist.

How can this be understood? (and what class does fn belong to?)

Stefanie Gauss
  • 425
  • 3
  • 9
  • 2
    see [AsyncFunction](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncFunction) which notes *'that AsyncFunction is not a global object'* but can be obtained with the following: `const AsyncFunction = async function () {}.constructor;` – pilchard May 16 '23 at 07:57
  • 1
    it seems like this question and answer can be a standalone Q&A on SO, rather than getting closed as a duplicate (the linked post on SO for closing this question doesn't really answer this question) – Stefanie Gauss May 16 '23 at 08:02
  • 1
    Either way it is unambiguously answered by even a cursory reading of the documentation. – pilchard May 16 '23 at 08:04
  • "*but `AsyncFunction` doesn't exist.*" - you mean there is no such global variable, not that the `AsyncFunction` constructor does not exist. So what? It seems you already understood this fine. – Bergi May 16 '23 at 08:12
  • The duplicate already has an excellent answer which perfectly explains the situation with a lot of background, even if the question comes at it from a different angle. No reason *not* to close this as a dupe. – deceze May 16 '23 at 08:25

0 Answers0