ECMAScript4ã¯Pythonåããã®ãï¼
http://weblogs.mozillazine.org/roadmap/archives/2006/02/js_and_python_news.html ãã:
js> function count(n) { for (var i = 0; i < n; i++) yield i; } js> g = count(10) [object Generator] js> g.next() 0 js> g.next() 1 js> two_to_nine = [i for i in g] 2,3,4,5,6,7,8,9 js> squares_to_20 = [i * i for i in count(20)] 0,1,4,9,16,25,36,49,64,81,100,121,144,169,196,225,256,289,324,361
Pythonã«ããyieldã«ããgeneratorè¨æ³ã¨comprehensionãå ¥ã£ãJavaScriptã§ãã注ç®ãã¹ãç¹ã¯ãç±æ¥ãPythonãã©ããã¨ããããããã®generatorã«ãã£ã¦ãç¬èªãªãã¸ã§ã¯ããé åã®ããã«è¦ããããã¨ããã¨ããã§ãï¼Perlã§ãããªãTie Arrayï¼ã
ããã¿ã«APIãå¢ããæ¹åã¯ããå¤ããä»å¾ã¯å©ç¨è ã¯ããã°ã©ãã³ã°è¨èªããã¤ã¤ã³ã¿ãã§ã¼ã¹ã¨ãã¦ã®ææ³ãç´æ¥ä½¿ããæ©è½å®è£ è ã¯è¨èªã®èå¾ã§åæ©è½ãçµåããã¨ããæ¹åã«é²ã¿ã¤ã¤ããã¾ã(railsãªããããã)ããããããã®ã¯è¨èªã®ãã®generatorã®ãããªæ©è½ã追å ããããã¨ã«ãã£ã¦ä¿é²ããã¾ãã
éã«ããã°ãããããã®ããã°ã©ãã³ã°è¨èªã¯ããã®ææ³ã®ä¸ã«èªç±ãªæ©è½ã追å ã§ãããã©ãããã«ããã£ã¦ããããããã¾ãããç¾ç¶ã¯çµåãããææ³ã®ã»ãã³ãã£ã¯ã¹ã«ã¯é åã ã¨ãããã·ã¥ã ã¨ããªãã¸ã§ã¯ãã ã¨ãã使ãããã®ã§ãããæä½éã¸ã§ããªãã¯ã§ããã°ããããã§ããããã ãã¨ããããã§ã¯ãªãã§ããããå¹æçã§ä½¿ããããææ³ãæ¡ç¨/çºæããã®ããã¨ããç¹ã¯ããéè¦ã«ãªãã®ã§ã¯ãªãã§ããããã