OOP - Prototype - Javascript

Hi there,
if I have the following constructor with a prototype:

function Bird(name, color) {
  this.name = name;
  this.color = color;
}
Bird.prototype.numWings = 2;

If I want to create an instance of Bird, like below:

let tweety = new Bird('tweety', 'grey');

and if I console.log(tweety) it doesn’t output the numWings property.

//output: Bird {name: 'tweety', color: 'grey'}

but if I console.log(tweety.numWings) i will get 2;

Why we don’t see the prototype property when we console log the whole object?

i think this depends on the implementation of the console.log.
In this case the implementor (via the js engine that runs the code) doesn’t print out the numWings defined on the prototype.

There may be other ways though to print it out.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.