
JavaScript String 對象
prototype 屬性允許您向對象添加屬性和方法
<b>注意:</b> Prototype 是全局屬性,适用于所有的 Javascript 對象。
object.prototype.name=value
所有主要浏覽器都支援 prototype 屬性
适用 prototype 屬性給對象添加屬性:
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);
以上執行個體輸出結果:
20000
