JavaScript 1.6 introduces several new features: E4X, several new Array
methods, and Array and String generics.
JavaScript 1.6 is supported in Firefox 1.5 and later.
E4X (since deprecated)
ECMAScript for XML (E4X) is a powerful technology for creating and processing XML content within JavaScript. We're going to continue to improve our E4X support, including adding transparent integration with the existing DOM, but developers who are building XML-based web applications can benefit from E4X support in Firefox 1.5.
You can still use the standard MIME type when using E4X:
<script type="text/javascript">
However, E4X syntax may conflict with the common practice of putting scripts into HTML comments (<!--...-->
) to hide them from old browsers. E4X may also conflict with the more modern practice of putting scripts within XML CDATA sections (<![CDATA{{mediawiki.external('...')}}]>
) to allow the symbols "<" and ">" in the script (note that this does not apply to HTML). If you see inexplicable syntax errors, add "; e4x=1" to the MIME type:
<script type="text/javascript; e4x=1">
Note that scripts in extensions always treat HTML comments as E4X literals. That is, the "e4x=1" is implicit.
E4X is documented in Processing XML with E4X.
Array extras
There are seven new Array
methods that can be separated into two categories, item location methods and iterative methods. The item location methods are:
indexOf()
- returns the index of the given item's first occurrence.lastIndexOf()
- returns the index of the given item's last occurrence.
The iterative methods are:
every()
- runs a function on items in the array while that function is returning true. It returns true if the function returns true for every item it could visit.filter()
- runs a function on every item in the array and returns an array of all items for which the function returns true.forEach()
- runs a function on every item in the array.map()
- runs a function on every item in the array and returns the results in an array.some()
- runs a function on items in the array while that function returns false. It returns true if the function returns true for any item it could visit.
For more information see Working with Arrays, or consult Nicholas C. Zakas' article, Mozilla's New Array Methods.
Array and String generics
For each ... in
for each ... in was introduced for iterating over an object's (or array's) property values instead of its keys/properties. This construct is also used in E4X.