由于java做多了,不习惯javascript类在类外部实现继承,找了点资料,实现了内部继承,就是在写类的时候,调用this.innerExtend(superClass),就可以继承superClass了。
  下面贴出2种方式:
/**
 * 在类定义外部实现继承
 
*/
Object.prototype.outerExtend
=function(superClass)
{
    
if (typeof superClass != 'function')
    {
        Status.showErrInfo(
"类继承错误:","<font color=red>由于超类结构有误,类外部继承失败!</font>","5秒后该提示自动消失");
        window.setTimeout(
"Status.setStatusShow(false)",5000);
        
return;        
    }
    
this.prototype = new superClass();
    
this.prototype.constructor = this//不加的话,constructor会为superclass
    this.superClass = superClass.prototype;    
}

/**
 * 在类定义内部实现继承
 
*/
Object.prototype.innerExtend
=function(superClass)
{
    
if (typeof superClass != 'function')
    {
        Status.showErrInfo(
"类继承错误:","<font color=red>由于超类结构有误,类内部继承失败!</font>","5秒后该提示自动消失");
        window.setTimeout(
"Status.setStatusShow(false)",5000);
        
return;        
    }
    
this.superClass = superClass;
    
this.superClass();
}
  大家慢慢看。

相关文章:

  • 2021-05-01
  • 2022-01-14
  • 2021-09-20
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-19
  • 2022-01-04
  • 2021-08-13
  • 2022-03-10
  • 2022-12-23
  • 2021-05-20
相关资源
相似解决方案