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

2018-02-07  本文已影响0人  大猪大猪

对比

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'
}
上一篇下一篇

猜你喜欢

热点阅读