I am learning about Javascript prototypes and made a Fiddle (http://jsfiddle.net/3MuZa/1/) with this javascript:
function Animal(name, sound) {
this.name = name;
this.sound = sound;
}
var dog = new Animal("Dog", "Bark");
console.debug(dog.__proto__);
Animal.prototype.makeSound = function() {console.log(this.sound);};
Interestingly, console.debug(dog.__proto__);
reveals that makeSound
is a method of the prototype of the Animal class.
However, I add that method to the prototype in a later line. Why is Console noting that the prototype has a makeSound
method if the control flow hadn't gotten to it yet in my code?
The console is "live". even if you do log it first, it will reflect later changes.
As far as i know, it behaves like this on objects, functions, arrays. But if you log strings, booleans and numbers, they print what they mean at the time they were logged.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With