function makeIteratorPrototype(func) {
return function(init) {
this.val = init
this.getNext = function() {
return this.val = func(this.val)
}
}
}
function test() {
p = makeIteratorPrototype(function(x){return x+1})
o = new p(10)
console.log(o.getNext())
console.log(o.getNext())
console.log(o.getNext())
}
test()
ZnVuY3Rpb24gbWFrZUl0ZXJhdG9yUHJvdG90eXBlKGZ1bmMpIHsKCXJldHVybiBmdW5jdGlvbihpbml0KSB7CgkJdGhpcy52YWwgPSBpbml0CgkJdGhpcy5nZXROZXh0ID0gZnVuY3Rpb24oKSB7CgkJCXJldHVybiB0aGlzLnZhbCA9IGZ1bmModGhpcy52YWwpCgkJfQoJfQp9CgpmdW5jdGlvbiB0ZXN0KCkgewkKCXAgPSBtYWtlSXRlcmF0b3JQcm90b3R5cGUoZnVuY3Rpb24oeCl7cmV0dXJuIHgrMX0pCglvID0gbmV3IHAoMTApCgljb25zb2xlLmxvZyhvLmdldE5leHQoKSkKCWNvbnNvbGUubG9nKG8uZ2V0TmV4dCgpKQoJY29uc29sZS5sb2coby5nZXROZXh0KCkpCn0KCnRlc3QoKQ==