Skip to content

Instantly share code, notes, and snippets.

@categulario
Last active January 3, 2016 12:59
Show Gist options
  • Select an option

  • Save categulario/8466296 to your computer and use it in GitHub Desktop.

Select an option

Save categulario/8466296 to your computer and use it in GitHub Desktop.
Native javascript generators
var gen = (function(){
this.next++;
return Math.pow(this.next, 2);
}).bind({'next': 0})
console.log(gen()); // 1
console.log(gen()); // 4
console.log(gen()); // 9
console.log(gen()); // 16
console.log(gen()); // 25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment