Skip to content

Instantly share code, notes, and snippets.

@davaynamore
Created April 11, 2019 15:18
Show Gist options
  • Save davaynamore/cf5b2a7057c6cea3c815ad337237571a to your computer and use it in GitHub Desktop.
Save davaynamore/cf5b2a7057c6cea3c815ad337237571a to your computer and use it in GitHub Desktop.
@@iterator for objects
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