下面贴出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();
}
大家慢慢看。
* 在类定义外部实现继承
*/
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();
}