To treat a concise method of an object literal as the generator method, or to treat a method of a class as the generator method, we can simply prefix it with the * character.
The generator method of a class is added to the prototype property of the class.
Here is an example to demonstrate how to define a generator method in the class:
class myClass { * generator_function() { yield 1; yield 2; yield 3; yield 4; yield 5; } } const obj = new myClass(); let generator = obj.generator_function(); console.log(generator.next().value); console.log(generator.next().value); console.log(generator.next().value); console.log(generator.next().value); console.log(generator.next().value); console.log(generator.next().done); console.log("generator_function" ...