Created
April 11, 2019 15:18
-
-
Save davaynamore/cf5b2a7057c6cea3c815ad337237571a to your computer and use it in GitHub Desktop.
@@iterator for objects
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 o = this; | |
var idx = 0; | |
var ks = Object.keys( o ); | |
return { | |
next: function() { | |
return { | |
value: o[ks[idx++]], | |
done: (idx > ks.length) | |
}; | |
} | |
}; | |
} | |
} ); | |
//for (var value of myObject) { | |
// console.log( value ); | |
//} | |
// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment