Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 418523 of New in JavaScript 1.6

  • Revision slug: Web/JavaScript/New_in_JavaScript/1.6
  • Revision title: New in JavaScript 1.6
  • Revision id: 418523
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment -Error, CleanUp.JavaScript/New_in_JavaScript/1.6 Web/JavaScript/New_in_JavaScript/1.6

Revision Content

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.

See also

Revision Source

<p>JavaScript 1.6 introduces several new features: E4X, several new <code>Array</code> methods, and Array and String generics.</p>
<p>JavaScript 1.6 is supported in <a href="/en-US/docs/Firefox_1.5_for_developers" title="Firefox_1.5_for_developers">Firefox 1.5</a> and later.</p>


<div class="warning">
  <h2 id="E4X_(since_deprecated)">E4X (since deprecated)</h2>
</div>

<p>ECMAScript for XML (<a href="/en-US/docs/E4X" title="E4X">E4X</a>) is a powerful technology for creating and processing <a href="/en-US/docs/XML" title="XML">XML</a> content within <a href="/en-US/docs/JavaScript" title="JavaScript">JavaScript</a>. We're going to continue to improve our E4X support, including adding transparent integration with the existing <a href="/en-US/docs/DOM" title="DOM">DOM</a>, but developers who are building XML-based web applications can benefit from E4X support in Firefox 1.5.</p>
<p>You can still use the standard MIME type when using E4X:</p>

<pre class="brush: html">
&lt;script type="text/javascript"&gt;
</pre>
<p>However, E4X syntax may conflict with the common practice of putting scripts into HTML comments (<code>&lt;!--...--&gt;</code>) to hide them from old browsers. E4X may also conflict with the more modern practice of putting scripts within XML CDATA sections (<code>&lt;![CDATA{{mediawiki.external('...')}}]&gt;</code>) to allow the symbols "&lt;" and "&gt;" in the script (note that this does not apply to HTML). If you see inexplicable syntax errors, add "; e4x=1" to the MIME type:</p>

<pre class="brush: html">
&lt;script type="text/javascript; e4x=1"&gt;
</pre>
<p>Note that scripts in extensions always treat HTML comments as E4X literals. That is, the "e4x=1" is implicit.</p>
<p>E4X is documented in <a href="/en-US/docs/E4X/Processing_XML_with_E4X" title="E4X/Processing_XML_with_E4X">Processing XML with E4X</a>.</p>



<h2 id="Array_extras">Array extras</h2>
<p>There are seven new <code><a href="/en-US/docs/JavaScript/Reference/Global_Objects/Array" title="JavaScript/Reference/Global_Objects/Array">Array</a></code> methods that can be separated into two categories, item location methods and iterative methods. The item location methods are:</p>
<ul>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Global_Objects/Array/indexOf" title="JavaScript/Reference/Global_Objects/Array/indexOf">indexOf()</a></code> - returns the index of the given item's first occurrence.</li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Global_Objects/Array/lastIndexOf" title="JavaScript/Reference/Global_Objects/Array/lastIndexOf">lastIndexOf()</a></code> - returns the index of the given item's last occurrence.</li>
</ul>
<p>The iterative methods are:</p>
<ul>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Global_Objects/Array/every" title="JavaScript/Reference/Global_Objects/Array/every">every()</a></code> - 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.</li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Global_Objects/Array/filter" title="JavaScript/Reference/Global_Objects/Array/filter">filter()</a></code> - runs a function on every item in the array and returns an array of all items for which the function returns true.</li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Global_Objects/Array/forEach" title="JavaScript/Reference/Global_Objects/Array/forEach">forEach()</a></code> - runs a function on every item in the array.</li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Global_Objects/Array/map" title="JavaScript/Reference/Global_Objects/Array/map">map()</a></code> - runs a function on every item in the array and returns the results in an array.</li>
  <li><code><a href="/en-US/docs/JavaScript/Reference/Global_Objects/Array/some" title="JavaScript/Reference/Global_Objects/Array/some">some()</a></code> - 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.</li>
</ul>

<p>For more information see <a href="/en-US/docs/JavaScript/Guide/Obsolete_Pages/Working_with_Arrays#Introduced_in_JavaScript_1.6" title="JavaScript/Guide/Working_with_Arrays#Introduced_in_JavaScript_1.6">Working with Arrays</a>, or consult Nicholas C. Zakas' article, <a class="external" href="https://www.webreference.com/programming/javascript/ncz/column4/index.html">Mozilla's New Array Methods</a>.</p>



<h2 id="Array_and_String_generics">Array and String generics</h2>
<ul>
  <li><a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array#Array_generic_methods" title="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array#Array_generics">Array generics</a></li>
  <li><a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String#String_generic_methods" title="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String#String_generics">String generics</a></li>
</ul>



<h2>For each ... in</h2>
<p><a href="/en-US/docs/JavaScript/Guide/Statements#for_each...in_Statement" title="JavaScript/Guide/Statements#for_each...in_Statement">for each ... in</a> was introduced for iterating over an object's (or array's) property values instead of its keys/properties. This construct is also used in <a href="/E4X" title="E4X">E4X</a>.</p>



<h2 id="See_also">See also</h2>
<ul>
  <li><a href="/en-US/docs/JavaScript/Guide/Predefined_Core_Objects#Working_with_Array-like_objects" title="https://developer.mozilla.org/en/JavaScript/Guide/Predefined_Core_Objects#Working_with_Array-like_objects">Working with Array-like objects</a>.</li>
<li><a href="/en-US/docs/tag/JavaScript" title="Articles tagged: JavaScript | MDN">Articles tagged: JavaScript</a></li>
</ul>


<!--languages( { "zh-cn": "cn/New_in_JavaScript_1.6" } )-->
Revert to this revision