Brennan posted a blog entry about the Firefox 2.0 beta release a couple of days ago that talks about a lot of the new features in the next Firefox release. This version seems to be an evolutionary release and not a revolutionary one. A lot of work has gone on in the internals of the code, and there are quite a few new developer fatures in this release, but there are still some really cool user centric features as well. Brennan talks a lot about the user features, so check them out. For more info, also look at the new features for end users that Mozilla provides.
I really want to look at some of the new features of Javascript though.
Javascript 1.7
Javascript is a great language that people often dislike for a variety of reasons. The main two reasons I've run across is:- Lack of understanding the features of the Javascript language
- Frustration with incompatible DOM implementations in browsers
Javascript 1.7 is picking up a lot of new features that more popular scripting langauges have such as Ruby and Python. I've drawn comparison to Javascript and Ruby before and a number of the new features in Javascript 1.7 only give them more feature parity.
Generators
Javascript 1.7 adds ayield
keyword. Yield allows
you leave a method of code and have the state of the method saved at that
point. When the method is called again, the last state of the code is resumed
(or continued) from the state of the last time the method was called. This is
often used for Iterators (another new feature). It can also be used to
implement things like Continuations which can
be used to create state machines and parsers.
Iterators
Building the the new Generator functionality, Javascript 1.7 is adding anIterator
object. While previous versions of Javascript
have allowed you to iterate over Array's and the like using for...each
, the Iterator allows you to build
your own Iterator to iterate over any object that you create.
Array comprehensions
Array comprehensions allow you to intialize an array taking advantage of the Generator code. You can iterate over a collection of items inline to the Array definition to populate the Array values.var myArray = [ "Cool " + i for (i in range(0, 10))];
Multiple Return Values
A method can return multiple values and have those values assigned to individual variables. This is an interesting feature found in Python. While you can always create a wrapper object to return the values, or use a construct like an Array, sometimes it is really handy to be able to just return multiple things from a method. No out parameters needed.
let for Explicit Scoping
let
allows you to define an explicit scope of a
variable. Just like var
makes a
variable so that it is not globally scoped, let
narrows the scope to a defined block. This allows you to
redefine the value of a var
(or
another let
) variable to a more
limited section of code, temporarily changing the value without
effecting the value outside of that defined block.
Lots of fun new features plucked from the best scripting and programming languages out there. The future looks bright for web client-side development. (Of course IE won't support this stuff for 10 years probably.)