0

When I initialize an object I want to set this.sound to the current value of Dog.sound.

The code below appears to make this.sound a reference to Dog.sound's value. How can I grab the value instead of a reference?

init: function() {
  this.sound = Dog.sound;
}
Don P
  • 60,113
  • 114
  • 300
  • 432
  • But I'm only using a single attribute of that object – Don P Jul 02 '13 at 03:06
  • 2
    If the value is a "primitive" type (string,number,boolean...) then it's not a reference. If it's an object (object,array,..) then you have to clone it. There are many questions in SO on how to clone arrays and objects. – elclanrs Jul 02 '13 at 03:07
  • @elclanrs - feel free to use as an answer and I'll accept – Don P Jul 02 '13 at 03:12

1 Answers1

2

If the value is a "primitive" type (string, number, boolean...) then it's not a reference. If it's an object (object, array...) then you have to clone it. There are many questions in SO on how to clone arrays and objects:

Community
  • 1
  • 1
elclanrs
  • 92,861
  • 21
  • 134
  • 171