Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我初始化一个对象时,我想将其设置this.sound为Dog.sound.
this.sound
Dog.sound
下面的代码似乎this.sound引用了Dog.sound's 的值。如何获取价值而不是参考?
init: function() { this.sound = Dog.sound; }
如果该值是“原始”类型(字符串、数字、布尔值...),则它不是引用。如果它是一个对象(对象、数组...),那么您必须克隆它。SO中有很多关于如何克隆数组和对象的问题: