Open In App

JavaScript Generator constructor Property

JavaScript Generator constructor property is used to return the Generator constructor function for the object. The function which is returned by this property is just the reference to this function, not a Generator containing the function’s name. The JavaScript number constructor, string constructor, and generator constructor return function Number() { [native code] }, function String() { [native code] }, and GeneratorFunction() { [native code] } respectively.

Syntax:



generator.constructor

Return Value: function GeneratorFunction() { [native code] }

Below are examples of the Generator constructor Property. 



Example 1: This example shows the basic usage of the Generator constructor property in JavaScript.




function* func() {}
console.log(func.constructor);

Output:

ƒ GeneratorFunction() { [native code] }

Example 2: This example uses the Generator constructor Property of Javascript.




function myGeeks() {
    function* func() { }
 
    console.log(func.constructor);
}
myGeeks()

Output:

JavaScript Generator constructor Property

Supported Browsers:

We have a complete list of JavaScript Generator methods, to check those please go through, the JavaScript Generator Reference article

Article Tags :