문제

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);

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 softwareengineering.stackexchange
scroll top