# 对象写法
let a = 1;
let b = 2;
let obj = {a,b};//a:1 b:2的简写
console.log(obj)
1
2
3
4
2
3
4
# 方法(函数)的简写
let obj = {
// sayHello: function(){
// console.log('helloWorld');
// }
sayHello(){
console.log('helloWorld');
},
}
obj.sayHello()//helloWorld
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# 传递字符串
let str = 'name'
let obj = {
[str]: 'huahua'
}
console.log(obj);
// name:huahua
//会把字符串的名字当做key传进对象里面去
1
2
3
4
5
6
7
2
3
4
5
6
7