Question

I am reading through Javascript: The Good Parts, and struggled to get my head around the section on prototypes.

After a little google, I came to the conclusion that it is to add properties to objects after the objects declaration.

Using this script gleamed from w3schools, I noticed that removing the line adding the prototype property had no effect. So what is the point?


//Prototyping

function employee(name,jobtitle,born)
{
this.name=name;
this.jobtitle=jobtitle;
this.born=born;
}

var fred=new employee("Fred Flintstone","Caveman",1970);
employee.prototype.salary=null; //  <---  try removing this line
fred.salary=20000;

document.write(fred.salary);

No correct solution

Licensed under: CC-BY-SA with attribution
scroll top