const target = { a: 1, b: 2};const source = { c: { deep: false }, d: [1,2,3] };let cloneObject = Object.assign(target, source); // or {...source}// deep clone methodlet deepObject = Object.assign(target, JSON.parse(JSON.stringify(source))); source.c.deep = true; source.d[0] = 4;console.log(cloneObject);console.log(deepObject);
浅克隆和深克隆单独执行,结果都正常,一起执行的话,输出如下:
期待浅克隆输出true, 深克隆输出false, 期待给出你的答案
手掌心
慕少森