Object.assign改变原始对象值

时间:2018-02-11 14:02:59

标签: javascript deep-copy

当我使用Object.assign()之前的值被覆盖时,我遇到了这个问题。

var blueprint = {
	name: {
  	first: "Default first name",
    last: "Default last name"
  }
};

var person1 = Object.assign( {}, blueprint );

console.log( blueprint.name.first ); // Gives me "Default first name"

person1.name.first = "John";

console.log( blueprint.name.first ); // Gives me "John"
console.log( blueprint.name.last ); // Gives me "Default last name"

问题是如何在保持我的蓝图安全的同时覆盖person1.name.first?

0 个答案:

没有答案