Prototype of object isn't object.property?

Based on the following example, the prototype of duck is apparently Bird.prototype. But shouldn’t the prototype of duck be duck.prototype?

duck.prototype.isPrototypeOf(duck) makes more sense for me. If the following example is correct, may I know why is the prototype of an obj (duck) equals to the obj’s constructor function’s prototype (Bird.prototype)?

function Bird(name) {
  this.name = name;
}

let duck = new Bird("Donald");

Bird.prototype.isPrototypeOf(duck);       //true

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36 Edg/93.0.961.52

Challenge: Understand Where an Object’s Prototype Comes From

Link to the challenge:

“duck” is a type of “Bird”.

The object you’ve assigned to the variable “duck” is just one instance of (a unique object of the type) “Bird”.

And you can create as many as you want – “bluetit”, “egret”, “flamingo”, “seagull” etc.

But they’re all “Bird” type objects. “duck” is just an arbitrary variable name, the object assigned to it is still a “Bird”.

If you want to have some functions attached to every bird you create, you do that by using "Bird"s prototype. Which then means every “Bird” you create has access to them, they’re shared.

So for another example, take Array. Say I have

let numbers = [1,2,3]

Or to keep it more like the Bird example:

let numbers = new Array(1, 2, 3);

And say I want to push the number 4 onto the end of that:

numbers.push(4);

There isn’t really a function push attached to the prototype of numbers, it’s attached to the prototype of Array.

numbers is a type of Array.

Array has a load of useful functions assigned to its prototype, which means every array you create inherits access to them.

2 Likes

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