11.1 A subset of JavaScript
11.1.1 Essence
Security of 11.1.2 subsets
11.2 Constants and local variables
<script type= "Text/javascript" >//keyword let has 4 ways to use //can be declared as a variable, as with Var //in the For or for/in loop, as a substitute for Var //defines a new variable in a statement block and displays the scope that specifies it //defines a variable within the scope of an expression that is only available in an expression functionoddsum (n) { let total= 0, result = []; for(Let x = 1; x <= n;x++) {Let odd= 2 * x-1; Total+=Odd; Result.push (total); } returnresult; } //Console.log (total);//referencerrrorConsole.log (Oddsum (5));</script>
View Code
11.3 Deconstruction Assignment
<script type= "Text/javascript" > // deconstructed Assignment (destructuring Assignment)let [x, y] = [+]; // Let x=1,y=2 [x, Y] = [× + 1,y + 1]; // x = x + 1,y = y + 1 [x, Y] = [y,x]; Console.log ([x, y]); </script>
View Code
11.4 iterations
11.4.1 For/each Cycle
<script type= "Text/javascript" > = {one:1,two:2,three:3} for in o) { console.log (p); } // For each (let V in O) { // Console.log (v); // }</script>
View Code
11.4.2 iterators
<script type= "Text/javascript" > Function counter (start) { = math.round (start); returnfunctionreturn nextvalue++;}}; } = Counter (+); = Serialnumbergenerator.next (); = Serialnumbergenerator.next (); </script>
View Code
11.4.3 Generator
<script type= "Text/javascript" > // Generator is an object that represents the current execution state of the generator function / * function Range (Min,max) {for (Let i = Math.ceil (min); I <= max;i++) { yield i; } } for (Let N in range (3,8)) { console.log (n); } */</script>
View Code
11.4.4 Array Derivation
<script type= "Text/javascript" >//JavaScript1.7 //array derivation is a technique for initializing array elements using another array or an iterative object . //Let evensquares = [x*x for (x in range (0,10)) if (x 2 = = = 0)]; //Let evensquares = []; //For (x in range (0,10)) { //if (x% 2 = = = 0) { //Evensquares.push (x*x); // } //} //[expression for (variable in object) if (condition)]</script>
View Code
11.4.5-Generator expression
<script type= "Text/javascript" > /leth = (f (x) for (x in G)); // Let lines = eachline (text); // Let trimmed = (L.trim () for (L in lines)); // Let nonblank = (L-in trimmed) if (l.length > 0 && l[0]! = ' # ')); </script>
View Code
11.5 Shorthand for functions
<script type= "Text/javascript" > // for simple functions, JavaScript1.8 introduces a shorthand form: expression closure functionfunctiontruefunctionfalse; </script>
View Code
11.6 Multiple Catch clauses
<script type= "Text/javascript" >/ * try { throw 1; } catch (E if e instanceof referenceerror) { } catch (e if E = = = "Quit") { } catch (e if typeof e = = = "str ing ") { } catch (e) { } finally { } */</script>
View Code
11.7 E4x:ecmascript for XML
Chapter 11th Subset and extension of JavaScript