// Object.is()用来比较两个值是否严格相等。它与严格比较服算符(===)的行为基本一致,不同之处只有两点:一是+0不等于-0,二是NaN等于自身
var a = Object.is(+0, -0);
var b = Object.is(NaN, NaN);
console.log(a);
console.log(b);

// Object.assign()
var target = {a: 1};
var source1 = {b: 2};
var source2 = {c: 3};
var result = Object.assign(target, source1, source2);
console.log(result);

// 增强的对象写法
var Person = {
    name: '张三',
    birth, // 等同于birth: birth
    // 等同于hello: function ()...
    hello () {
        console.log('我的名字是', this.name);
    }
};

// 属性名表达式
var lastWord = 'last word';
var a = {
    "first word": "hello",
    [lastWord]: "world"
};

console.log(a["first word"]); // hello
console.log(a[lastWord]); // world
console.log(a["last word"]); // world

var suffix = " word";
var a = {
    ["first" + suffix]: "hello",
    ["last" + suffix]: "world"

};

console.log(a["first word"]); //hello
console.log(a["last word"]); //world

小渝人儿
1.1k 声望850 粉丝

前端工程师