javascript - JS object, need explanation of what's happening and why -
this question has reply here:
console.log() async or sync? 2 answersthis code pet
:
function pet() { this.vitals = new vitals(); } function vitals() { this.hunger = 5; this.thirst = 0; this.emotions = { happy: true, sad: true } }
below calling , forth:
$(document).ready(function () { var pet = new pet(); console.log(pet); pet.vitals.emotions.happy = false; console.log(pet); });
this console:
question: why happy
false
in both readouts, , not sec one?
probably because console.log
can update info printed if underlying object reference updated afterwards. seek create reference called pet2
see trick.
by way, should check this , this.
javascript json object
No comments:
Post a Comment