0

考虑下面的代码:

//for extend classes
function extend(subClass,superClass){
  var F=function(){};
  F.prototype=superClass.prototype;
  subClass.prototype=new F();
  subClass.prototype.constructor=subClass;
}
//basic sender object
function Sender(){}
Sender.prototype = {
  ...
};
//interface
//extend method 1:
function BackendAdmin(){}
BackendAdmin.prototype.Sender = function(){};
extend(BackendAdmin.Sender,Sender); //will generate prototype of undefined error
//extend method 2:
function BackendAdmin(){
  this.Sender = function(){};
  extend(this.Sender,Sender);// Seems can not be extended
}
// instance
var myadmin=new BackendAdmin();
myadmin.Sender.StartLoading(); // do not have method for method 2.

在这种情况下,我想在 BackendAdmin 中创建一个 sender 实例,它继承了基本 sender 类的方法,此外,如果需要,我还需要重写 BackendAdmin 中的 sender 方法。但是,除非我使用这样的东西,否则它似乎在这两种情况下都不起作用:

this.sender = new Sender();

如何使用扩展功能?

4

0 回答 0