Just (hopefully) a quick question to figure out how Javascript handles objects. I'm not used to JS, so it came as a surprise, so I want to double check!
Let's say I have an object:
function food(price) { this.price = price || 100; } var myFood = new food(100);
And then save this object in two arrays:
var foo = []; var bar = []; foo.push(myFood); bar.push(myFood);
Do I understand correctly that all I do here is store the GUIDE for myFood? I do not create a copy of the object? So if I were, say:
foo[0].price = 50;
Will there be [0] .price ALSO == 50, since it stores a link to myFood, and this is myFood, which actually influenced its price, not foo or bar?
Thank you very much in advance! I saw several threads that mention this issue as part of a wider publication, but I just wanted to get all this to make sure! Best wishes
source share