Open In App

JavaScript Generator constructor Property

Last Updated : 02 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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.

Javascript




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


Output:

Æ’ GeneratorFunction() { [native code] }

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

Javascript




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


Output:

JavaScript Generator constructor Property

JavaScript Generator constructor Property

Supported Browsers:

  • Chrome
  • Edge 
  • Firefox
  • Opera
  • Safari

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


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads