Deconstruction purposes assignment

 // 1. The exchange value of the variable 
    the let X =. 1 ; 
    the let Y = 2 ; 
    [X, Y] = [Y, X]
     // 2. plurality of return value from a function 
    // function can return a value to return a plurality 
    // can be placed in an array or an object may also be utilized to return destructuring assignment 
    function Example () {
         return [l, 2,3 ]; 
    } 
    the let [A, B, C] = Example (); 
    Example ()     // returns an array 






    function Example () {
         return { 
            foo: . 1 , 
            bar: 2 
        }; 
    } 
    the let {foo, bar}= Example ();
     // Returns an object 



    // 3. function parameter defines 
    // parameter values is an ordered set of 
    function F ([X, Y, Z]) {...} 
    F ([ 1,2 , 3 ]); 

    // parameter values is a set of unordered 
    function F ({X, Y, Z}) {...} 
    F ({Z: 3, Y: 2, X:. 1 }) 
    
    // . 4 . json data extracting 
    the let jsonData = { 
        ID: 42 is , 
        Status: 'OK' , 
        data: [ 867,5309 ] 

    }; 
    the let {ID, Status, data: Number} = jsonData; 
    the console.log (ID, Status, Number) 


    // default value of 5. the function parameters
    jQuery.ajax = function (url,{
        async = true,
        beforeSend = function(){},
        cache = true,
        complete = function(){},
        crossDomain = false,
        global = true,
    } = {}){

    }

    // 6.遍历Map解构
    const map = new Map();
    map.set('first','hello')
    map.set('last','world')
    for(let [Key,value] of map){
        console.log(key + 'is' + value);
        
    }

Deconstructing the assignment of function parameters

function add ([x, Y]) {
         return x + Y; 
    } 
    add ([ 1,2 ])
     // parameter is an array surface but add transmission parameters to be deconstructed when the array parameters x and Y 



    [[ 1,2 ], [3,4-]]. Map (([A, B]) => A + B)
     // [3,7]
    

Deconstructing the assignment of values ​​and Boolean values

// will first turn when the righthand side of the assignment deconstructed numeric or Boolean objects 
    the let {toStrig: S} = 123 ; 
    S === Number.prototype.toString // to true 
    the let {toString: S =} to true ; 
    s === Boolean.prototype.toStrig; // to true 
    // numerical and Boolean wrapper object has properties toString can therefore take the value of the variable s 
    


    // destructuring assignment principles are not objects as long as the equal sign or the right array 
    // to first convert it to an object as null and undefined can not be converted to an object so destructuring assignment will complain

 

Guess you like

Origin www.cnblogs.com/treasurea/p/11228450.html