Skip to content
  • 🔥 TRENDING

    World linux erneuter angriff javascript globalfeed
    1
    0 Votes
    1 Posts
    0 Views
    No one has replied
  • 0 Votes
    13 Posts
    0 Views
    kimapr ☭K
    @fiore@brain.worm.pink @darkwiiplayer@tech.lgbt though i thinked about it for 3 seconds, and i realize that it's pretty trivial to implement exactly this behavior in javascript without language changes Number.prototype[Symbol.iterator] = function*(i){for(let i=0;i<this;i++)yield i} then typing [...10] would produce [0,1,2,3,4,5,6,7,8,9] ... Or in a "foreach" loop: for (let i of 10) console.log(i); A better, more useful idea would be something like this: Number.prototype.to = function*(j){for(let i=+this;i<j;i++)yield i}; for (let i of (0).to(10)) console.log(i); to implement iterable ranges as can be found in rust