What is the point of the prototype method?
Posted
by
Mild Fuzz
on Programmers
See other posts from Programmers
or by Mild Fuzz
Published on 2011-09-06T13:08:04Z
Indexed on
2012/09/06
21:51 UTC
Read the original article
Hit count: 355
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);
© Programmers or respective owner