标签:targe tor put out 浅拷贝 mat foo 环境 proc
module.exports = { getItem, setItem, clear }; // 等同于 module.exports = { getItem: getItem, setItem: setItem, clear: clear };
var o = { method() { return "Hello!"; } }; // 等同于 var o = { method: function() { return "Hello!"; } };
let propKey = ‘foo‘; let obj = { [propKey]: true, [‘a‘ + ‘bc‘]: 123 };
Object.is(‘foo‘, ‘foo‘) // true Object.is({}, {}) // false
var target = { a: 1 }; var source1 = { b: 2 }; var source2 = { c: 3 }; Object.assign(target, source1, source2); target // {a:1, b:2, c:3}
var obj1 = {a: {b: 1}}; var obj2 = Object.assign({}, obj1); obj1.a.b = 2; obj2.a.b // 2
class Point { constructor(x, y) { Object.assign(this, {x, y}); } }
const merge = (target, ...sources) => Object.assign(target, ...sources);
const DEFAULTS = { logLevel: 0, outputFormat: ‘html‘ }; function processContent(options) { options = Object.assign({}, DEFAULTS, options); console.log(options); // ... }
let z = { a: 3, b: 4 }; let n = { ...z }; n // { a: 3, b: 4 }
标签:targe tor put out 浅拷贝 mat foo 环境 proc
原文地址:http://www.cnblogs.com/nankeyimeng/p/7275181.html