Async generator function objects created with the AsyncGeneratorFunction
constructor are parsed when the function is created. This is less efficient than declaring a generator function with an async function*
expression and calling it within your code, because such functions are parsed with the rest of the code.
All arguments passed to the function, except the last, are treated as the names of the identifiers of the parameters in the function to be created, in the order in which they are passed.
Note: Async generator functions created with the AsyncGeneratorFunction
constructor do not create closures to their creation contexts; they are always created in the global scope.
When running them, they will only be able to access their own local variables and global ones, not the ones from the scope in which the AsyncGeneratorFunction
constructor was called.
This is different from using eval
with code for an async generator function expression.
Invoking the AsyncGeneratorFunction
constructor as a function (without using the new
operator) has the same effect as invoking it as a constructor.