Created
February 26, 2017 17:22
-
-
Save Kolenov/7f8445bc5cb406eef84491fd7ea4498b to your computer and use it in GitHub Desktop.
Custom Iterator
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
Object.defineProperty(myObject, Symbol.iterator, { | |
enumerable: false, | |
writable: false, | |
configurable: true, | |
value: function () { | |
var obj = this; | |
var idx = 0; | |
var ks = Object.keys(obj); | |
return { | |
next: function () { | |
return { | |
value: obj[ks[idx++]], | |
done: (idx > ks.length) | |
}; | |
} | |
}; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment