typeScript 析构表达式

针对对象的析构表达式

function getStock(){

return {

code:"IBM",

price:{

price1:12,

price2:23

}

}

}

var {code:codex,price:{price1}} = getStock();

console.log(codex);

console.log(price1);

//针对数组的析构表达式

var array = [1,2,4,6,7];

var [number1,number2] = array;

console.log("数组的析构表达式");

console.log(number1);

console.log(number2);

var [number1,,,number2] = array;

console.log("数组的析构表达式");

console.log(number1);

console.log(number2);

var [number1,number2,...others] = array;

console.log("数组的析构表达式 结合操作符others");

console.log(number1);

console.log(number2);

console.log(others);

 

 

 

你可能感兴趣的:(typeScript,typeScript,析构表达式)