2、ES6 === destructuring 解构

解构 Destructuring

function breakfast(){
  return ['苹果', '香蕉', '橘子'];
}

var tmp = breakfast(),
    apple = tmp[0], banana = tmp[1], orange = tmp[2];

alert(apple + ', ' + banana + ', ' + orange);// 苹果, 香蕉, 橘子

// 改进一下
function breakfast(){
  return ['苹果', '香蕉', '橘子'];
}

let [apple, banana, orange] = breakfast();

alert(apple + ', ' + banana + ', ' + orange);// 苹果, 香蕉, 橘子

function breakfast(){
  return {apple : '苹果', banana : '香蕉', orange : '橘子'};
}

let {apple : apple, banana : banana, orange : orange} = breakfast();

alert(apple + ', ' + banana + ', ' + orange);// 苹果, 香蕉, 橘子


你可能感兴趣的:(ES6)