AsyncGeneratorFunction() constructor

The AsyncGeneratorFunction() constructor creates AsyncGeneratorFunction objects.

Note that AsyncGeneratorFunction is not a global object. It could be obtained by evaluating the following code.

const AsyncGeneratorFunction = async function* () {}.constructor;

The AsyncGeneratorFunction() constructor is not intended to be used directly, and all caveats mentioned in the Function() description apply to AsyncGeneratorFunction().


new AsyncGeneratorFunction(functionBody)
new AsyncGeneratorFunction(arg0, functionBody)
new AsyncGeneratorFunction(arg0, arg1, functionBody)
new AsyncGeneratorFunction(arg0, arg1, /* … ,*/ argN, functionBody)

AsyncGeneratorFunction(arg0, functionBody)
AsyncGeneratorFunction(arg0, arg1, functionBody)
AsyncGeneratorFunction(arg0, arg1, /* … ,*/ argN, functionBody)

Note: AsyncGeneratorFunction() can be called with or without new. Both create a new AsyncGeneratorFunction instance.



Using the constructor

The following example uses the AsyncGeneratorFunction constructor to create an async generator function.

const AsyncGeneratorFunction = async function* () {}.constructor;
const createAsyncGenerator = new AsyncGeneratorFunction("a", "yield a * 2");
const asyncGen = createAsyncGenerator(10); => console.log(res.value)); // 20


ECMAScript Language Specification
# sec-asyncgeneratorfunction-constructor

Browser compatibility

BCD tables only load in the browser

See also