看到这个题目:

http://blog.zhaojie.me/2010/06/code-for-fun-iterator-generator-yield-in-javascript.html

 

我也做了一个答案如下:

 

 

function range(minInclusive, maxExclusive) {
	this.next = function(){
		return (minInclusive < maxExclusive - 1)? 
			new range(minInclusive + 1, maxExclusive)
			: null;
	};

	this.value = minInclusive;

	return this;
}

for (var iter = range(0, 10); iter; iter = iter.next()) {
    document.write(iter.value + "<br />");
}

 

 

相关文章:

  • 2021-08-25
  • 2021-06-12
  • 2022-03-09
  • 2022-12-23
  • 2021-09-01
  • 2022-12-23
  • 2022-02-06
  • 2021-12-06
猜你喜欢
  • 2022-01-15
  • 2021-10-13
  • 2021-11-03
  • 2021-11-16
  • 2022-12-23
  • 2021-08-06
  • 2021-05-17
相关资源
相似解决方案