Last active
April 11, 2019 17:49
-
-
Save cymerrad/e690fbcd884c6b604d2ef0e18bf72acb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var Foo = { | |
*[Symbol.iterator]() { | |
for (let [idx, val] of this.nums.entries()) { | |
yield label => `${label}: ${val} | |
(${idx+1} / ${this.nums.length})`; | |
} | |
}, | |
bar([x = 1, y = 2, ...nums] = []) { | |
this.nums = [x, y, ...nums]; | |
} | |
}; | |
Foo.bar([10,20,30,40,50]); | |
for (let f of Foo) { | |
console.log( f("Foo") ); | |
} | |
/* Output: | |
Foo: 10 | |
(1 / 5) | |
Foo: 20 | |
(2 / 5) | |
Foo: 30 | |
(3 / 5) | |
Foo: 40 | |
(4 / 5) | |
Foo: 50 | |
(5 / 5) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment