DEV Community

Discussion on: You don't know spread operator !

sadanandpai profile image
Sadanand Pai

Very simple if used generator

Number.prototype[Symbol.iterator] = function* () {
for (let i = 1; i <= this; i++) yield i;

parsyvalentin profile image
Valentin PARSY

Exactly, I wanted to keep this simple for people not knowing anything about this subject (like me 2 weeks ago =D )
But from there you can go absolutely nuts ! The sky is the limit ! You can actually declare the iteration protocol inside a class, then all your "instances" are iterables.