Tuesday, April 22nd, 2008

Talking about JavaScript 1.7, 1.8 and 1.9 before we get to 2.0

Category: JavaScript

Is this JavaScript that would run in a current browser?

javascript

  1. function square_of(x) x * x;
  2.  
  3. players.sort(function(x,y) y['score'] - x['score']);

Yup. This is JavaScript 1.8 and 1.7, also known as Pythonizing Javascript ;)

Tiago Silveira discusses these lambda expressions, as well as Generators:

javascript

  1. function actions() {
  2.   for (f in document.forms) {
  3.     yield document.forms[f].action
  4.   }
  5. }

list comprehensions, let:

javascript

  1. function showItems(items) {
  2.   for (let i in items) {
  3.     // the variable i has the scope of this block.
  4.     ShowElement('item_' + i);
  5.   }
  6. }
  7. // Using comprehensions:
  8. showItems([ i for ( i in obj ) if ( i > 3 ) ])
  9.  
  10. // Using generators:
  11. showItems( i for ( i in obj ) if ( i > 3 ) )

And more.

Then we hear from John Resig that the JavaScript 1.9 planning meeting happened and we really hope for some SPLAT fun gets in as well as his own hope for built-in Function.prototype.bind and a native JSON encoder/decoder. Others were looking for setPropertyIsEnumerable, and Douglas Crockford has his own thoughts.

Posted by Dion Almaer at 8:27 am
5 Comments

+++--
3.6 rating from 10 votes

5 Comments »

Comments feed TrackBack URI

Sorry, am I being a bit slow. Is this post suggesting that the main browsers already support lambda expressions? FF3 does, IE7 doesn’t.

I got really excited for a moment.

Comment by kim3er — April 22, 2008

Interesting, I agree with all of Douglas Crockford’s suggestions except the removal of eval() (it does have some valid uses). His ideas would really increase the power and usability of JS.

Comment by Ryura — April 22, 2008

@kim3r: “a current browser” not “all current browsers” ;)

Comment by Matt — April 22, 2008

@Matt: roger that, makes sense now. Has anyone tried Lambda expressions in IE8?

Comment by kim3er — April 23, 2008

Which current browser are you talking about? Firefox? :)

Also, make sure you specify the language as “javascript1.8”, not just “javascript”, or it won’t work in Firefox.

Comment by jdempcy — April 23, 2008

Leave a comment

You must be logged in to post a comment.