ES6 - 吃鸡入门系列 ~ Object对象

对比

es6

全写

let user = {
  username:'lake',
  login:function(){
    //exec login service
  }
}

方法简写

let user = {
  username:'lake',
  login(){
    //exec login service
  }
}

属性引用简写

let username = 'lake';
let user = {
  username,
  login(){
    //exec login service
  }
}

对象合并

let user = {
  username:'lake',
  age:24
}

let admin = {
  ...user,
  type:'ADMIN'
}

合并后的对象

{
  username:'lake',
  age:24,
  type:'ADMIN'
}

你可能感兴趣的:(ES6 - 吃鸡入门系列 ~ Object对象)