const a = new Object();
对象字面量
const a = {};
属性增强写法
es5
const a = '123' const obj = { a:a }
es6
const a = '123' const obj = { a } // 属性从同名变量找
函数增强写法
es5
`
const a = {
a:function(){
}
}
`
es6
`
const a = {
a(){
}
}
`
字符串模版
const skill = '安邦' const david =
文能${skill}
ES6对象键计算表达式
var heat = '50%'; var field = 'Rock and Roll'; var music = { [field.toLowerCase()]: heat } console.log(music); // Object {rock and roll: "50%"}
对象解构
let music = { type: 'rock', heat: '50%' }; let { type, heat } = music; console.log(type, heat); // rock 50%
对象解构 重命名
let music = { type: 'rock', heat: '50%' } let { type: aaa, heat: bbb } = music; console.log(aaa, bbb); // rock 50%
数组解构
let people = [20, 25, 30] let [young, oldYoung] = people; console.log(young, oldYoung) // 20 25