6, based ES6

function

    // default function arguments so that the same name is not allowed by the parameter 
    function Fn (name, name, Age) {
         // the same name as the back cover parameters preceding 
        the console.log (name, name); 
    } 
    Fn ( "webcyh", 21 is );
     function Test (name, Age = 21 is ) { 
        the console.log (name, Age); 
    } 
    // parameter when the transmission is not empty or undefined Effective 
    Test ( "webcyh" , undefined); 
    Test ( "webcyh", null );
     // variable parameter 
    function test2 (name, ... values) { 
        the console.log (name); 
        // variable parameter returns an array of 
        the console.log (values); 
    } 
    test2 ("webcyh", 1,2,2,2,2,2 );
     // arrow from the function performed when no parameters or parameter arrow plurality of brackets need 
    // if only one statement and function return value may not be required braces 
    // when the return value is an object to add () 
    (() => the console.log ( "Hello" )) (); 

    var F = V => V; 

    the console.log (F ( . 1 ));
     // arrow function does this, super, arguments and new.target binding. 
    // this point to the outside and this can not be used as a constructor new new 
    the console.log ((() => ({name: "webcyh", Age: 21 is })) ());
     function Test3 () { 
        the setInterval ( () => { 
            the console.log ( the this II.A); 
        }, 1000 ); 
    };
    test3.call({a:"webcyh"});

 Here this point to the benefits of this outside

 this target has been very very large head, the callback function, often see this code var self = this, this order will be passed to the callback function outside, then with the arrow function, need not do so, the direct use of this on the line

Test = const { 
        Age: 21 is , 
        getAge :() => the console.log ( the this .age) 
    } 
    const test1 = { 
        Age: 21 is , 
        getAge () { 
            the console.log ( the this .age); 
        } 
    } 
    var Age. 1 = ; 
    test.getAge (); 
    test1.getAge (); 
    // Note the click event when listening can lead to not bind to the corresponding elements above

 

Guess you like

Origin www.cnblogs.com/webcyh/p/11459682.html