Firefox 2.0 to Feature New JavaScript 1.7

Despite some indications to the contrary this week, the Mozilla Foundation did not release its next version of the Firefox browser, which is still being widely, publicly tested under Release Candidate 2. As Mozilla's vice president for engineering, Mike Schroepfer, told BetaNews on Friday, Firefox releases take place on a qualitative basis, not on a deadline or time scale. The organization will release the next production version of the browser when it feels it's ready for prime time.

One of the new browser's key elements, and perhaps the beneficiary of the greatest amount of change, is its new JavaScript interpreter. As more Web sites take advantage of the new benefits of Asynchronous JavaScript -- especially as they embed objects or functionality from Google and Microsoft Windows Live -- the JavaScript interpreter may play a much more active role, not only in the operation of the browser but in the implementation of Web-based applications.

With many in the original JavaScript development team from Netscape now working with Mozilla -- including Brendan Eich, JavaScript's creator and Mozilla's CTO -- the developers of Firefox 2.0 see an opportunity to propagate the component that could replace the HTML rendering engine as the Web's most prominent and influential component.

Developers are now starting to formalize additions to the JavaScript language to be rolled out with version 1.7 of the interpreter, which will premiere on the world's Web stage the day Firefox 2.0 is released.

"If you look at Firefox in general, the JavaScript engine is one of the really shining examples of the platform," Schroepfer remarked. "It's one of the reasons why Web developers prefer it, because it's very fast for most operations, it's very compliant, it's one of the most widely used JavaScript engines out there."

As he reminded us, not only does Firefox' JavaScript engine execute embedded scripts in Web pages (including AJAX scripts), but it also executes client-side code for use in Firefox extensions, which are embedded directly into the browser.

For that reason, the upgrade of the interpreter to version 1.7 will be of prime importance, especially as JavaScript begins to take on more of the programming features of newer, compelling scripting languages such as Python and Ruby. "JavaScript 1.7...implements a whole host of new features that were really inspired by the takeoff of other languages that have become popular, like Python and Ruby," stated Schroepfer, "so we take the JavaScript language to that next level."

Python has proven to be perhaps the tightest and most adaptable general purpose scripting language thus far developed, although Perl and PHP continue to have substantial followings. As JavaScript takes on more Python-like features, Firefox developers may be compelled not only to redefine the Web page, but also to build onto the browser itself.

"I think what we focused on in [upgrading] the core platform," Schroepfer said, "was, how do we put the right core primitives in the main platform to make Firefox both a great development platform and a great platform for end users to use, and then how do we leverage the extensibility of that platform through extensions to let developers effectively write their own tools that they need to write, in order to build these vast, distributed Web-based applications?"

On the programming level, one example of the changes JavaScript developers will see is with two new features that other scripting languages have made good use of, called generators and iterators. One example shows the use of a re-iterative loop that generates the first 100 numbers in the famous Fibonacci sequence (which was used as a benchmark back in the days when "microcomputers" were slower).

In typical JavaScript construction, for the loop to report its progress with each iteration, it would have to invoke a callback function that steps execution outside the loop clause, so that it could perform a document.write instruction each time.

With generators and iterators instead, a variable can be declared and assigned the function containing the reiterative loop as its "value." Here, the variable acts more like an object. The loop clause that counts the first numbers in the sequence exists outside the function, so the main body of the program has control over how many times the function is entered.

Execution steps into the function for one round -- one iteration -- by means of the .next method, which acts as the iterator. The function "knows" it's being used for multiple iterations, even though it doesn't maintain the loop. It gracefully passes execution back to the main body, which has the loop, by means of the all-new yield statement. This is the generator.

As Schroepfer told BetaNews, JavaScript 1.7 is an interim build, a "check point" on the way to finally implementing JavaScript 2.0, which is based on (actually a superset of) the ECMAscript 4.0 proposal that Netscape made to the ECMA standards body in 2003, and which incorporates Macromedia's (now Adobe's) ActionScript 2.0.

"Firefox 2.0, and the release of JavaScript 1.7, [comprise] the first kind of checkpoint along that path, where we're adding things like array comprehension, some Let expressions and iterator expressions that people are used to in the Python syntax, to make it easier to do things like loop over an array of elements and apply something to them - a very common operation on the Web."

Schroepfer added that, just like every other Mozilla project, the production of JavaScript 1.7 and 2.0 are taking place out in the open, in full cooperation with not only the ECMA working group but also with major implementers of JavaScript including Adobe, Google, and Microsoft.

BetaNews will feature more with Mike Schroepfer and more of the new under-the-hood features of Firefox 2.0 as its release approaches.

© 1998-2014 BetaNews, Inc. All Rights Reserved. Privacy Policy.