Home > Web Front-end > JS Tutorial > Introduction to new features of W3C Group's JavaScript 1.8_Basic knowledge

Introduction to new features of W3C Group's JavaScript 1.8_Basic knowledge

WBOY
Release: 2016-05-16 18:52:37
Original
1167 people have browsed it

JavaScript 1.8 is planned to be available as part of Gecko 1.9 (which will be merged into Firefox 3). This is only a small update compared to JavaScript 1.7, but it does contain some traces of evolution towards ECMAScript 4/JavaScript 2. JavaScript 1.8 will also include all new features in JavaScript 1.6 and JavaScript 1.7.
Using JavaScript 1.8
In order to use the new features of JavaScript 1.8 in HTML, you need to write as follows:

<script>When using JavaScript shell and JavaScript XPCOM components, Or XUL <BR> element, the latest JS version (JS1.8 in Mozilla 1.9) is automatically used. <BR>If you need to use the new keywords "yield" and "let", you have to specify version 1.7 or higher, because the code you have written may use these two keywords as variables name or function name. If you are not using any new keywords, you do not need to specify the JavaScript version. <STRONG>Expression closure<BR> <BR>This newly added feature is actually a convenient way to write simple functions, making the language more similar to typical Lambda notation. <BR>JavaScript 1.7 and older versions: <BR>function(x) { return x * x; } <BR>JavaScript 1.8: <BR>function(x) x * x <BR>This syntax allows you to omit curly braces and 'return' statements -- implicitly Do their job. If you write it this way, it will only look shorter on the surface and has no other benefits. <BR>Example: <STRONG><BR>Simple way of binding event handler: <BR>document.addEventListener("click", function() false, true); <BR>Put this definition with JavaScript Use one-write array functions in 1.6: <BR>elems.some(function(elem) elem.type == "text"); <STRONG><BR>Generator expression<BR>This new addition feature that allows you to easily create generators (introduced in JavaScript 1.7). Normally you previously needed to create a custom function that contained a yield, but this new feature allows you to create a standalone generator handle using a syntax similar to the array concept. <BR>In JavaScript 1.7, you may need to write code like the following to create a custom generator for an object: <BR>function add3(obj) { <BR>for ( let i in obj ) <BR>yield i 3; <BR>} <BR>let it = add3(someObj); <BR>try { <BR>while (true) { <br>document.write(it.next() "<BR>n "); <BR>} <BR>} catch (err if err instanceof StopIteration) { <br>document.write("End of record.<BR>n"); <BR>} <STRONG><BR>at In JavaScript 1.8, you can avoid having to rebuild the generator function and use a generator expression instead: <BR>let it = (i 3 for (i in someObj)); <BR>try { <BR>while (true) { <br>document.write(it.next() "<BR>n"); <BR>} <BR>} catch (err if err instanceof StopIteration) { <br>document. write("End of record.<BR>n"); <BR>} <BR>Generator expressions can also be passed to a function like numbers. It is very worth noting that the generator is only run when absolutely necessary to be useful (not pre-configured as the condition of the typical array concept). This difference can be seen in the following example: <STRONG><BR>Using JavaScript 1.7 array concepts<BR>handleResults([ i for ( i in obj ) if ( i > 3 ) ]); <BR> function handleResults( results ) { <BR>for ( let i in results ) <BR>// ... <BR>} <BR>Use JavaScript 1.8 generator expressions<BR>handleResults( i for ( i in obj ) if ( i > 3 ) ); <BR>function handleResults( results ) { <BR>for ( let i in results ) <BR>// ... <BR>} <BR>The largest difference between these two examples The difference is that when using a generator expression, you only need to loop through the 'obj' structure once, in total; while in the first example, it will be looped again during recursion. <BR>JavaScript 1.8.1 <BR>JavaScript 1.8.1 is included in Gecko 1.9.1 (will be integrated into Firefox 3.5). This version has only a few updates, mainly focused on adding just-in-time compilation tracing, see: Tracemonkey just-in-time compiler. <BR>Of course, the more significant change is the removal of the callback branch in the API and the replacement of the callback operation, see: detailed in this newsgroup posting. <BR>Added part <BR>Object.getPrototypeOf() <BR>This new method returns the prototype of a specified object. <BR>This method will return the prototype of the specified object. <BR>New trim methods on the String object <BR>The String object now has trim(), trimLeft(), and trimRight() methods. ()method.</script>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template