Javascript and Generators
Could Javascript be getting generators, iterators and list comprehensions? This post from Brendan Eich is a status update about the future of Javascript that mentions the possibility (From Ajaxian).
Categories: javascript
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,361Categories: javascript

1 Comments:
I'd like to see those features. JS2 probably won't be standardized by IE 7's release, will it?
Post a Comment
<< Home