Class-Loop
Creates an Iterator for the class, to use in for-of loop
Problem
In Javascript, for-of
loop cannot be used in object.
Eg:
{ thisproperty0 = 'prop0'; thisproperty1 = 'prop1'; }// Create an instanceconst instance = ; for let i of instance properties; // Above will throw 'TypeError: instance is not iterable' error
Using 'Class-Loop' module
- TypeScript
import ClassLoop
class.
;
Using with a class
; property0: string; property1: string; { super; thisproperty0 = 'prop0'; thisproperty1 = 'prop1'; } const instance = ; const properties = ;for const i of instance properties; console;/* Output[ { key: 'property0', value: 'prop0' }, { key: 'property1', value: 'prop1' }]*/
- Javascript
const ClassLoop = ;
Using with a class
const ClassLoop = ; { super; thisproperty0 = 'prop0'; thisproperty1 = 'prop1'; } const instance = ; const properties = ;for let i of instance properties; console; /* Output[ { key: 'property0', value: 'prop0' }, { key: 'property1', value: 'prop1' }]*/
Override loop function in child class.
- TypeScript
; property0: string; property1: string; { super; thisproperty0 = 'prop0'; thisproperty1 = 'prop1'; } // Write your own loop function : any let counter = 2; return next: : { return value: 'test' + counter done: counter <= -1 ; } ; const instance = ; const properties = ;for let i of instance properties; console; /* Output[ 'test1', 'test0' ]*/
- Javascript
const ClassLoop = ; { super; thisproperty0 = 'prop0'; thisproperty1 = 'prop1'; } // Write your own loop function : any let counter = 2; return next: : { return value: 'test' + counter done: counter <= -1 ; } ; const instance = ; const properties = ;for let i of instance properties; console; /* Output[ 'test1', 'test0' ]*/