es6(四): 对象的扩展

发布时间:2019-08-09 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了es6(四): 对象的扩展脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
// 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@H_475_126@

脚本宝典总结

以上是脚本宝典为你收集整理的es6(四): 对象的扩展全部内容,希望文章能够帮你解决es6(四): 对象的扩展所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。