当我使用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?