This time I will bring you a detailed explanation of the destructuring assignment of ES6. What are the precautions for using the destructuring assignment of ES6?The following is a practical case, let's take a look.
@1 Destructuring assignment of array;let [a,b,c]=[1,2,3]; console.log(a,b,c) //1 2 3 ---------------------------------------------------------------- let [a=true]=[]; console.log(a) //a=true; ---------------------------------------------------------------- let[a=true]=[undefined]; let[b=true]=[null] console.log(a,b) //a=true,b=null
ObjectPointer
typeof null ==>object;而undefined可以认为在下面两种情况会出现;
let[a=true]=[undefined]; let[a=true]=[ ];
let {foo,bar}={bar:"liuhf",foo:true}; //跟键的顺序没有关系;
Destructuring assignment of string;
const [a,b,c,d,e,f]="liuhee"; console.log(a,b,c,d,e,f); // l i u h e e
let json = { a: '对', b: '象' } //对象的函数解构; function fun({ a, b = 'jspang' }) { console.log(a, b); } fun(json); //数组的函数解构; let arr = ["liu", "hai"] function fun1([a, b]) { console.log(a, b); } fun1(arr); console.log("------------"); //或者; function fun2(a, b) { console.log(a, b); } fun2(...arr);
Entry, output, module analysis of webpack3.x
The above is the detailed content of Detailed explanation of destructuring assignment in ES6. For more information, please follow other related articles on the PHP Chinese website!