ES6 - arrow functions as functions, objects deconstruction

ES6 - Arrow function:

// arrows and function of the extended es6 

// ES5 wording 
   // function the Add (A, B) { 
   //     return A + B; 
   // } 
   // the Add (1,2); //. 3 

    function ADD1 (A , B =. 1 ) {
         IF (A == 0 ) {
             the throw  new new Error ( 'ZERO IS A' ); 
        } 
        return A + B; 
    } 
    // the console.log (ADD1 (0)) // Uncaught Error: A IS ZERO active thrown 

    // strict mode 
    function the Add (A, B) {
         'use strict'
         return A + B; 
    } 
  the console.log (the Add (. 1)) // NaN3 
  the console.log (the Add (1,2)) // . 3 

//    Get the number of parameters 
    the console.log (add.length)   // 2 

    function ADD2 (A, B =. 1 ) {
         return A + B; 
    } 
    the console.log (add2.length) // . 1 is the number of parameters obtained when the parameters must be passed to the output of a copying 0 

// arrow functions   

// arrow functions are not allowed in the new function can not be written by arrow constructor 
// method body when not only the line braces 
var ADD3 = (a, B =. 1) => a + B; 
the console.log (ADD3 ( 2)) // . 3 

// method body in multiple lines when needed braces 
var ADD4 = (A, B) => {
    console.log( "---");
    return a + b;
}
console.log(add4(1,2)) //3

 Deconstruction function object

// function object deconstructing 
the let JSON = {
     'A': 'Ananiah' ,
     'B': 'Jason'  
} 
the console.log (json.a) // output Ananiah 
function Fun ({A, B = 'default' }) { 
    the console.log (A, B) // output ananiah Jason 
} 
Fun (JSON);

 

Guess you like

Origin www.cnblogs.com/Ananiah/p/11070323.html