写法简化

let obj = {};
let obj1 = new Object();
let obj2 = Object.create(null); // 传入原型
var obj = {
	name: 'zhangsan',
  sleep: function() {},
  // 方法书写方式增强
  eat() {
  	console.log(1);
  }
}

obj.eat();
let firstName = 'ai';
let secondName = 'xiaoye';
let name = 'ai xiaoye';
let person = {
  [firstName + secondName]: name
}

console.log(person);
// { aixiaoye: 'ai xiaoye' }

⭐️ 对象拓展

var obj = {};
obj[true] = 'f'; // 会转成字符串'true'
obj[3] = 'b';
obj[obj] = 'bb';
console.log(obj['true']);

Untitled

const a = {a: 1};
const b = {b: 2};

const obj = {
	[a]: 'valueA',
  [b]: 'valueB'
} 

console.log(obj);

Untitled