Javascript Class Generator Methods

Introduction

The following code adds a generator method to the class.

class MyClass {/*  w w  w .  j  av a2 s . c om*/

    *createIterator() {
        yield 1;
        yield 2;
        yield 3;
    }

}

let instance = new MyClass();
let iterator = instance.createIterator();
console.log(iterator);
console.log(iterator);
console.log(iterator); 



PreviousNext

Related