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 652931 of New in JavaScript 1.8

  • Revision slug: Web/JavaScript/New_in_JavaScript/1.8
  • Revision title: New in JavaScript 1.8
  • Revision id: 652931
  • Created:
  • Creator: fscholz
  • Is current revision? No
  • Comment moved out code samples and guide material that does not belong into a release note page but in given reference pages instead

Revision Content

The following is a changelog for JavaScript 1.8. This version was included in Firefox 3 and is part of Gecko 1.9. See {{ Bug("380236") }} for a tracking development bug for JavaScript 1.8.

Using JavaScript 1.8

In order to use some of the new features of JavaScript 1.8 in HTML, use:

 <script type="application/javascript;version=1.8"> ... your code ... </script>

Another way (not recommended) to do this is to use the deprecated <script> language attribute and define it as "JavaScript1.8".

When using the JavaScript shell, JavaScript XPCOM components, or XUL <script> elements, the latest JS version (JS1.8 in Mozilla 1.9) is used automatically ({{ Bug(381031) }}, {{ Bug(385159) }}).

The features that require the use of the new keywords "yield" and "let" require you to specify version 1.7 or higher because existing code might use those keywords as variable or function names. The features that do not introduce new keywords (such as generator expressions) can be used without specifying the JavaScript version.

New features in JavaScript 1.8

Changed functionality in JavaScript 1.8

Changes in destructuring for..in

One change that occurred in the release of JavaScript 1.8 was a bug fix related to the key/value destructuring of arrays introduced in JavaScript 1.7. Previously it was possible to destructure the keys/values of an array by using for ( var [key, value] in array ). However, that made it impossible to destructure the values of an array - that were arrays (i.e., when an iterator returns an array of the current key-value pair). This has been resolved now. ({{ Bug("366941") }}). One can, however, use  for ( var [key, value] in Iterator(array)).

Revision Source

<div>
 <section class="Quick_links" id="Quick_Links">
  {{ListSubpages("/en-US/docs/Web/JavaScript/New_in_JavaScript", "2", "0", "1")}}</section>
</div>
<p>The following is a changelog for JavaScript 1.8. This version was included in <a href="/en-US/Firefox/Releases/3">Firefox 3</a> and is part of Gecko 1.9. See {{ Bug("380236") }} for a tracking development bug for JavaScript 1.8.</p>
<h2 id="Using_JavaScript_1.8">Using JavaScript 1.8</h2>
<p>In order to use some of the new features of JavaScript 1.8 in HTML, use:</p>
<pre class="brush: html">
 &lt;script type="application/javascript;version=1.8"&gt; ... your code ... &lt;/script&gt;
</pre>
<p>Another way (not recommended) to do this is to use the deprecated <code>&lt;script&gt;</code> language attribute and define it as "JavaScript1.8".</p>
<p>When using the <a href="/en-US/docs/Mozilla/Projects/SpiderMonkey/Introduction_to_the_JavaScript_shell" title="Introduction_to_the_JavaScript_shell">JavaScript shell</a>, JavaScript XPCOM components, or XUL <code>&lt;script&gt;</code> elements, the latest JS version (JS1.8 in Mozilla 1.9) is used automatically ({{ Bug(381031) }}, {{ Bug(385159) }}).</p>
<p>The features that require the use of the new keywords "yield" and "let" require you to specify version 1.7 or higher because existing code might use those keywords as variable or function names. The features that do not introduce new keywords (such as generator expressions) can be used without specifying the JavaScript version.</p>
<h2 id="New_features_in_JavaScript_1.5">New features in JavaScript 1.8</h2>
<ul>
 <li><a href="/en-US/docs/Web/JavaScript/Guide/Closures#Expression_closures">Expression closures</a>.</li>
 <li><a href="/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators">Generator expressions</a>. Allowing you to simply create generators (which were introduced in <a href="/en-US/docs/Web/JavaScript/New_in_JavaScript/1.7" title="New_in_JavaScript_1.7">JavaScript 1.7</a>). Typically you would have to create a custom function which would have a yield in it, but this addition allows you to use array comprehension-like syntax to create an identical generator statement.</li>
 <li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce"><code>Array.prototype.reduce()</code></a></li>
 <li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight"><code>Array.prototype.reduceRight()</code></a></li>
</ul>
<h2 id="Changed_functionality_in_JavaScript_1.5">Changed functionality in JavaScript 1.8</h2>
<h3 id="Changes_in_destructuring_for..in_(Make_mention_of_this_change_in_a_new_destructuring_section)">Changes in destructuring <code>for..in</code></h3>
<p>One change that occurred in the release of JavaScript 1.8 was a bug fix related to the key/value <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment" title="New in JavaScript 1.7">destructuring of arrays</a> introduced in JavaScript 1.7. Previously it was possible to destructure the keys/values of an array by using <code>for ( var [key, value] in array )</code>. However, that made it impossible to destructure the values of an array - that were arrays (i.e., when an iterator returns an array of the current key-value pair). This has been resolved now. ({{ Bug("366941") }}). One can, however, use &nbsp;<code>for ( var [key, value] in Iterator(array))</code>.</p>
Revert to this revision