标签:object undefined null col 有一个 var == 字符串 覆盖
let obj = { [propKey]: true, [‘a‘ + ‘bc‘]: 123 };
let obj = { [‘h‘ + ‘ello‘]() { return ‘hi‘; } };
obj.hello()
//会自动将对象转为字符串 //[keyA]和[keyB]得到的都是[object Object],所以[keyB]会把[keyA]覆盖掉,而myObject最后只有一个[object Object]属性。 const keyA = {a: 1}; const keyB = {b: 2}; const myObject = { [keyA]: ‘valueA‘, [keyB]: ‘valueB‘ }; myObject // Object {[object Object]: "valueB"}
Object.assign(undefined) // 报错 let obj = {a: 1}; Object.assign(obj, undefined) === obj // true Object.assign(obj, null) === obj // true
var v1 = ‘abc‘; var v2 = true; var v3 = 10; var obj = Object.assign({}, v1, v2, v3); console.log(obj); // { "0": "a", "1": "b", "2": "c" } //因为只有字符串有可枚举属性
标签:object undefined null col 有一个 var == 字符串 覆盖
原文地址:https://www.cnblogs.com/lftBlogs/p/14658747.html