複製程式碼 代碼如下: 批次實作物件導向的實例 <BR>window.onload = function(){ <BR>function Person(name,age){ <BR>this.name = name; <BR>this.age = age; <BR>} <BR>Person.prototype.showName = function() { <BR>alert(this.name); <BR>}; <BR>function extend(parent,child,method){ <BR>function a(){ <BR>parent.apply(this,arguments); <this,arguments); <BR>child.apply(this,arguments); <BR>}; <BR>for(var i in parent.prototype){ <BR>a.prototype[i]=parent.prototype[i]; <BR>} <BR>for(var i in method){ <BR>a.prototype[i] = method[i]; <BR>} <BR>return a; <BR>};//參數為父級建構子,子層級建構子,子級方法<BR>var int = extend(Person,function(name,age,job){ <BR>this.job = job; <BR>}, <BR>{ <BR>showjob: function(){ <BR>alert(this.job); <BR>} <BR>} <BR>); <BR>var oc=new int('俠客',24,'工作'); <BR> oc.showjob(); <BR>} <BR> 物件導向繼承實例 開始展示批次實作物件導向的實例