<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=null;
bill.salary=20000;
document.write(bill.salary);
</script>
20000
本文通过创建一个员工对象并为其原型添加属性,演示了如何使用JavaScript的原型链来访问对象属性。具体展示了如何定义一个构造函数,创建对象实例,并为对象原型及实例添加属性,最后通过document.write输出实例的属性值。

被折叠的 条评论
为什么被折叠?



