Prototypes


#1

I don't need help its just that I am not understanding what prototypes do exactly . Can someone
let me know?
(Thanks in advanced)


#2

Well, the first codecademy exemple is very poor so it's kinda hard to get it the first time. But really it just let you inherit properties you've already written so you dont have to write it again. This is a better exemple I suppose.

function Penguin(name) {
    this.name = name;
    this.numLegs = 2;
};
function Emperor(name) {
    this.name = name;
};

So far so good right? Two objects with its own properties

Emperor.prototype = new Penguin(); //This will make Emperor(); inherit all properties and methods if applicabe
var emperor = new Emperor("Von Habsburg"); //This will create a new Emperor
console.log(emperor.numLegs); //Guess what it will do

You probably guessed right. It will print 2 legs. Even tho the class emperor doesnt have numLegs as a property Penguin() has and Emperor() will take it as if you wrote it in


#3

What do you mean by that
(sorry for late response I have bad internet)