每个函数
都有一个属性叫做prototype。这个prototype的属性值是一个对象
,默认的只有一个叫做constructor
的属性,指向这个函数本身。
prototype原型作为对象,属性的集合,除了constructor外,还可以自定义的增加许多属性
语法
object.prototype.name=value
例子
function employee(name,job,born)
{
this.name=name;
this.job=job;
this.born=born;
}
var bill=new employee("Bill Gates","Engineer",1985);
employee.prototype.salary=null;
bill.salary=20000;
document.write(bill.salary);
结果
20000