object解构赋值

时间:2020-01-19 00:39:26   收藏:0   阅读:113
let options = {
  title: ‘menu‘,
  width: 100,
  height: 200
}
//如果简写,变量名必须和属性名一致
let {title,width,height} = options
console.log(title,width,height)
let {title:title2,width,height} = options
console.log(title2,width,height)

let {title, ...last} = options
console.log(title,last)

//嵌套对象
let options = {
  size: {
    width:100,
    height:200
  },
  items:[‘he‘,‘ee‘],
  extra: true
}
let {size:{width,height},items:[item1],extra} = options
console.log(width,height,item1,extra)
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!