Monday, February 20th, 2006

The Future of JavaScript: an Update from Brendan Eich

Category: Firefox, JavaScript, Programming, Python

>Brendan Eich has posted a status update on some of the work going into the upcoming JavaScript 2, aka ECMAScript Edition 4 (ES4). One feature that should look familiar to Python hackers are generators and iterators, as seen in the following example taken from a console session:

< view plain text >
  1. js> function count(n) {
  2.     for (var i = 0; i < n; i++)
  3.         yield i;
  4. }
  5. js> g = count(10)
  6. [object Generator]
  7. js>
  8. 0
  9. js>
  10. 1
  11. js> two_to_nine = [i for i in g]
  12. 2,3,4,5,6,7,8,9
  13. js> squares_to_20 = [i * i for i in count(20)]
  14. 0,1,4,9,16,25,36,49,64,81,100,121,144,169,196,225,256,289,324,361

Why go with the Python style and syntax?

Given the years of development in Python and similarities to ECMAScript in application domains and programmer communities, we would rather follow than lead. By standing on Python’s shoulders we reuse developer knowledge as well as design and implementation experience. The trick then becomes not borrowing too much from Python, just enough to gain the essential benefits: structured value-generating continuations and a general iteration protocol.

Brendan also mentioned that support for XUL in Python is almost done, and should land back into the main Firefox codebase from the DOM_AGNOSTIC2_BRANCH soon.

The official spec that will lead the way is ECMA TG1, which is being worked on by Brendan along with colleagues from Mozilla, Adobe, and Microsoft. Lets hope Brendan’s vision for JavaScript’s future will become reality:

My gut says that we will successfully evolve JS into a much stronger language, with a better and more standard library ecosystem, for the next ten years of its life. I will wager that other browsers will follow the ES4 standard, possibly even in 2007.

Related Content:


Comments feed TrackBack URI

If you want JavaScript iterator functionality today, take a look at the Mochikit Javascript library. It’s also based on Python, so the ideas should be very similar.

Comment by sean — February 20, 2006

I was kind of hoping for Ruby-like blocks and iterators.

[1, 2, 3].each(function(item) { /* mooo */ });

Comment by Daniel Schierbeck — February 20, 2006

[JavaScript / Python] JavaScript Gets More Pythonic

[via Ajaxian] Brendan Eich has blogged a status report on the progress of work on the upcoming JavaScript 2 (a.k.a. ECMAScript 4).He talks about an upcoming feature: Python-style generators, iterators and list comprehensions in JavaScript. His examples…

Trackback by The Farm: The Tucows Developers' Hangout — February 20, 2006

Microsoft was on the spec for E4X as well and even wrote an E4X engine for IE but it’s still sitting on the shelf…

Comment by Alex Bosworth — February 20, 2006

I believe Mozilla has already added some Lisp-like blocks and iterators, like These were only added recently, though.

Comment by Ian Bicking — February 21, 2006

Why don’t we solve the problem and make JavaScript 2.0 = Python ?

Seems to solve a lot of issues.

Comment by Mike — February 21, 2006


Prototype Dissected  &nbsp;

73 Resources on Windows opensource and/or freeware – Listible!…ws-opensource-and2For-freeware &nbs…

Trackback by The.RSS.Reporter — February 21, 2006

that js shell looks cool just like the python one. how do i get it?

Comment by akash — February 21, 2006

Mike – there’s just that minor piffling detail with backward compatibility :). Besides, current Javascript actually has working closures and true anonymous functions; Python doesn’t.

Comment by Pete — February 21, 2006

Daniel Schierbeck:

I also wish they’d include Ruby-like blocks and iterators… In the meantime, I like to use this one-line each for my JS code:
function each(a, f) {for(var i=0; i<a.length; i++) f(a[i])};
which allows one to write something similar to what you wanted:
each([1, 2, 3], function(e) { alert(e) })

Comment by eliazar — February 21, 2006


Comment by Mikael Bergkvist — February 21, 2006

Here’s another vote for Ruby-esque blocks and iterators.

Comment by Adam Connor — February 21, 2006

1 vote against ruby iterators.

Comment by Matt — February 21, 2006

Ruby-like Blocks and iterators are possible today:

Array.prototype.each = function(f) {
for (var i = 0; i

Comment by Mathias Karstädt — February 21, 2006

Sorry, once again:

Array.prototype.each = function(f) {
for (var i = 0; i < this.length; i++) {
[1,2,3,4].each(function(item) { alert(item)})

Comment by Mathias Karstädt — February 21, 2006

“that js shell looks cool just like the python one. how do i get it?”
I think it’s from the Rhino project (requires Java to run and Ant to build).

Comment by shadytrees — February 21, 2006

Ignore that build thing. You can run it with already built js.jar via “java -jar js.jar”.

Comment by shadytrees — February 21, 2006

Mathias Karstädt:

Yes, you could have a ruby-esque each in JS by making each a method of class Array. The problem with that approach is that there are other important collection of objects one would also like to traverse with each. For instance, a childNodes returns a NodeList object in Firefox (and who knows what in IE), and document.getElementsByTagName returns objects of a class I haven’t been able to ascertain (theoretically it should be a NodeList object too but that’s false).

You could try to solve this, somewhat rough-handedly, by making each a method of class Object, but while that will work in Firefox it won’t in IE.

Ruby solves this problem by having an Enumerable class of which every collection class is a children, but to my knowledge there’s nothing like that in JS right now.

And that’s why I prefer to have each as a top-level method, as I described in a previous comment.

Comment by eliazar — February 21, 2006

Eliazar: You might be interested in Prototype’s enumerable: Eliazar, it adds an enumerable support to javascript. I don’t think that collections like nodeList would have them builtin, though its possible with some of the core object extensions that prototype does.

Enumerable doc here:

Comment by Rob Sanheim — February 21, 2006


Thanks for the pointer! I was interested, of course, and I’m quite impressed with Sam’s implementation of Enumerable, it’s elegant and complete. I guess this is the passage that explains the Prototype-way to handle the collections I was mentioning:

The $A() function converts the single argument it receives into an Array object.. One suggested use is to convert DOM NodeLists into regular arrays, which can be traversed more efficiently.

This is all great, and I’ll be using $A() a lot, but I wonder why Prototype doesn’t include the Enumerable methods inside such collections by default (as it does for Arrays)…

(Oh, and a little bug report: you can’t see a blockquote’s text in the Live Preview, it’s the same color as the background.)

Comment by eliazar — February 21, 2006

regarding, Ruby-like blocks and iterators.
Javascript has prototype based class, which make it possible for javascript behave like Ruby, Python, Scheme..etc….

Array.prototype.reduce=function(func) {
var l=this.length;
var s=”;
for (var i=0;i

Comment by Tree — February 21, 2006

[...] Ajaxian » The Future of JavaScript: an Update from Brendan Eich (tags: ajax Programming javascript) [...]

Pingback by SIXFACE » Blog Archive » links for 2006-02-21 — February 21, 2006

[...] “Given the years of development in Python and similarities to ECMAScript in application domains and programmer communities, we would rather follow than lead.” (via:reddit) [...]

Pingback by “The future of JavaScript is Pythonesque” at soypunk — February 21, 2006

“Ruby solves this problem by having an Enumerable class of which every collection class is a children, but to my knowledge there’s nothing like that in JS right now.”

Actually thats not quite right. Enumerable is a module/mixin that is imported into certain classes. Theres a difference.

Comment by Luke Redpath — February 21, 2006

[...] In a recent post on by Brendan Eich on his Brendan’s Roadmap Updates Mozilla blog and echoed on Ajaxian it would appear that our favourite programming languge is about to land on the desktop in the Firefox browser in more ways than one. [...]

Pingback by Uwe’s weblog » Blog Archive » Python influence in JavaScript and Firefox — February 21, 2006


Heh, I knew someone would point that out… You’re correct, of course. It’s just that sometimes I prefer to be approximately right, rather than exactly wrong.

Comment by eliazar — February 21, 2006

[...] A summary of the future holds for the javascript language from Brendan Eich. Thanks Steve! [...]

Pingback by The Web Design Blog — February 22, 2006

Cool, Python with braces. Now that wasn’t so painful, was it?

Comment by John Mudd — February 22, 2006

Note that the Flash 8.5 player out in beta (with Eclipse-based IDE for Flex) has a sophisticated JIT VM based on ECMAscript 4. (Macromedia helped drive the spec, in fact.)

/not into platform religious wars, use whatever makes you productive.

Comment by Jolly Roger — February 23, 2006

Man, I haven’t used python in a while. I guess i better brush up on it :)

Comment by hacker not cracker — March 17, 2006

[...] Ajaxian FirefoxAs soon as Firefox 1.5 comes out, people want to play with some of the shiny nobs. SVG: How Did The Moon Get Into Orbit? One of the early post-release examples of SVG support on Firefox 1.5 was this [...]

Pingback by Firefox Customization | IE look and feel for the Firefox Browser — May 10, 2006

The Future of JavaScript.

I’m a big fan of JavaScript….

Trackback by David Findley's Blog — May 22, 2006

I thought they said ECMA4 is going to look like Actionscript 3???

Comment by jonah — September 21, 2007

Leave a comment

You must be logged in to post a comment.