Skip to content

Instantly share code, notes, and snippets.

@Sparkenstein
Created February 25, 2019 09:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sparkenstein/d5c5b0e00108c51a7d121749bd9cc4db to your computer and use it in GitHub Desktop.
Save Sparkenstein/d5c5b0e00108c51a7d121749bd9cc4db to your computer and use it in GitHub Desktop.
Symbol.iterator on number prototype
const { log } = console;
Number.prototype[Symbol.iterator] = function () {
let i = 0;
const end = this;
return {
next() {
return {
value: i++,
done: i > end,
};
},
};
};
// for-of
for (i of 2) {
log(i);
}
// array-destructuring
const [, a] = 10;
log(a)
// spread operator
const a = [...10]
log(a)
// rest parameters
function test(...a){
log(a)
}
test(...3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment