Difference in logic among Objects, instances and prototypes

Tell us what’s happening:
Hi everyone,

This is not strictly a request for coding, that is pretty straight forward but on principles.
Can someone please clarify some concepts about Objects, instances and prototypes?

The lesson says:
“A more efficient way is to set the prototype to a new object that already contains the properties. This way, the properties are added all at once:”

Ok, but why do we need a new object? For what I see the Bird object exists already and we are adding some more properties in form of prototypes so that they are not duplicates on all the objects (or maybe I should say on all the instances of that objec): so where is the new object?

Second, reading the documentation about prototypes it transpires that the prototype is the responsible for the inheritance system (called chain) but are not object instances without any prototype property already inheriting the object properties by reference (or other logic)?

If the prototypes save us from “duplicate” properties are we actually duplicating memory spaces when we create an instance of an object? And this does not happen when we prototype the property of that object resulting in a sort of cave of primordial features that are referenced on every instance created from a prototype property with no new space allocated?

If so, why not all the properties of an object are created as prototype by default? This actually seem to be the case in Java Script but why we declare an object this way then:

function Bird() {
  this.name = "Albert";
  this.color  = "blue";
  this.numLegs = 2;
}

Should not all the proprieties be declared with the prototype propriety then to avoid duplication?
(also terminology is very confusing )

Thank you for any explanation or redirection to some paper or documentation
L

Your code so far


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

Dog.prototype = {
// Only change code below this line
numLegs : 4,
eat : function(){console.log('I am eating')},
describe : function(){console.log('My name is' + this.name)}
};

Your browser information:

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

Challenge: Change the Prototype to a New Object

Link to the challenge:

  • Complete all the challenges of OOP step by step, you’ll get all your answers
  • After the completion of OOP challenges if you feel that you didn’t get your answers, I would suggest to repeat solving all the challenges at least one more time, hope, you’ll get it.

So the answer is in what I read. Alright, thank you