Skip to content

Instantly share code, notes, and snippets.

@Kolenov
Created February 26, 2017 17:22
Show Gist options
  • Save Kolenov/7f8445bc5cb406eef84491fd7ea4498b to your computer and use it in GitHub Desktop.
Save Kolenov/7f8445bc5cb406eef84491fd7ea4498b to your computer and use it in GitHub Desktop.
Custom Iterator
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