1、对象属性值简写
const name = 'xiaoliang',
age = 18;
function hobby() {
console.log('singing');
}
//字面量
const person = {
// name:name,
// age:age
name,
age,
hobby
}
console.log(person);
2、对象内部方法简写
//简写对象内部的方法,不用写function
let cat = {
whell: 4,
// set:function(){
// console.log('几个');
// }
set() {}
}
3、可计算属性名
//可计算属性名,如果对象的key值是一个变量,就用[]添加
let person1 = {};
let value = "hello WaRen"
person1["wa" + "ren"] = "蛙人"
person1[value] = "value"
console.log(person1);
let key = "name"
let person2 = {
[key + "ll"]: "蛙人", // 在对象字面量中这样使用[]方括号定义key是Es6语法
[`${key}_test`]: "test"
}
console.log(person2);
4、重复的字面量属性前面的被覆盖
//重复的字面量属性
let dog = {
color: 'white', //被覆盖
color: 'black'
}
console.log(dog.color);
5、新增Object.is()方法,严格比较
// console.log(NaN == NaN); //false
// console.log(0 == 0); //true
// console.log(+0 == -0); //true
// console.log(Object.is(NaN, NaN));
6、Object.assign()
// Object.assign(targrt,obj1,obj2...中所有的属性合并到target中)
let a = {
aa: 12
}
let b = {
bb: 13
}
let newobj = Object.assign({}, a, b);
console.log(newobj);