1.定義函數,函數中定義類對象 f1=function(){ //定義類 function Pannel(name){ this.name = name; this.print = function(){ console.info(this.name); }; } //擴展類方法成員 Pann... ...
1.定義函數,函數中定義類對象 f1=function(){ //定義類 function Pannel(name){ this.name = name; this.print = function(){ console.info(this.name); }; } //擴展類方法成員 Pannel.prototype.show = function(){ alert(this.name); } //返回類 return Pannel; } 2.執行函數,獲得類 Pannel = f1(); 3.調用類,new出對象 var pannel = new Pannel("張三"); console.info(pannel.name); pannel.print(); pannel.show();