prototype 属性使您有能力向对象添加属性和方法。 注意是 对象 对象 对象
<html>
<body>
<script type="text/javascript">
function employee(name,job,born)
{
this.name=name;
this.job=job;
this.born=born;
}
var bill=new employee("Bill Gates","Engineer",1985);
console.log(employee.prototype)
console.log(bill);
</script>
</body>
</html>
console.log(employee.prototype)
console.log(employee.prototype)
这里我打印了一下employee.prototype, 没有prototype属性, 现在我添加个这属性
<html>
<body>
<script type="text/javascript">
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=8000;
bill.salary=20000;
console.log(employee.prototype)
console.log(bill);
</script>
</body>
</html>
可以看到打印的对象中多出了 salary:8000 和 salary :20000 这两个属性, 如果继续添加操作一样。
删除属性:employee.prototype.salary=null;