fork download
  1. function makeIteratorPrototype(func) {
  2. return function(init) {
  3. this.val = init
  4. this.getNext = function() {
  5. return this.val = func(this.val)
  6. }
  7. }
  8. }
  9.  
  10. function test() {
  11. p = makeIteratorPrototype(function(x){return x+1})
  12. o = new p(10)
  13. console.log(o.getNext())
  14. console.log(o.getNext())
  15. console.log(o.getNext())
  16. }
  17.  
  18. test()
Success #stdin #stdout 0.06s 10928KB
stdin
Standard input is empty
stdout
11
12
13