JavaScript prototype 屬性

定義和用法
prototype 屬性允許您向?qū)ο筇砑訉傩院头椒?/p>
注意: Prototype 是全局屬性,適用于所有的Javascript對(duì)象。
語法
object.prototype.name=value
瀏覽器支持
所有主要瀏覽器都支持 prototype 屬性
實(shí)例
實(shí)例
適用 prototype 屬性給對(duì)象添加屬性:
<script>
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;
fred.salary=20000;
document.write(fred.salary);
</script>
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;
fred.salary=20000;
document.write(fred.salary);
</script>
以上實(shí)例輸出結(jié)果:
20000
嘗試一下 ?

更多建議: