Skip to content

Instantly share code, notes, and snippets.

@rajatjain-21
Last active December 26, 2020 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajatjain-21/4cf60fbfbe285164c56de05e8c9ac3ec to your computer and use it in GitHub Desktop.
Save rajatjain-21/4cf60fbfbe285164c56de05e8c9ac3ec to your computer and use it in GitHub Desktop.
let obj = {
a: 32,
b: 34
}
Object.defineProperty(obj, Symbol.iterator, {
configurable: false,
enumerable: false,
writable: false,
value: function() {
let _this = this;
let idx = 0;
let objkeys = Object.keys(_this);
return {
next: () => {
return {
value: _this[objkeys[idx++]],
done: (idx > objkeys.length)
};
}
}
}
});
for (let val of obj) {
console.log(val);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment