Ext.TabPanel多次继承以后报错
最近在项目对Ext.TabPanel进行继承发现一个问题
就是当对Ext.TabPanel进行多次的继承之后,给items里面家东西就会报错.
代码如下:
var TestExtend=Ext.extend(Ext.TabPanel,{})function TeEE(){
TeEE.superclass.constructor.call(this);
}
Ext.extend(TeEE,TestExtend,{/* //代码中加上这一段就会报错
items: [{
title: 'Tab 1',
html: 'A simple tab'
},{
title: 'Tab 2',
html: 'Another one'
}]*/})
// 当在TestExtend或者是TeEE中加上items时 执行这个会报错
check_TP2=new TeEE();//执行 这个则不会报错
check_TP2=new TestExtend();
function TeEE(config){
this.items=[
{
title: 'Tab 1',
html: 'A simple tab'
},{
title: 'Tab 2',
html: 'Another one'
}
]
TeEE.superclass.constructor.call(this, config);
}
Ext.extend(TeEE,TestExtend,{})
多层继承肯定是没问题的
问题出在你继承的时候,不要添加引用的属性,例如你这里的 items,这种引用类型在创建多个实例的时候是公用的,一个实例修改 items 后其他实例访问时已经不是之前那个了。子类新加的属性最好是值类型,例如:string,number,bool等等
另外你这里添加的 items 属性在父类中已经定义,非常危险
[code="java"]function TeEE(config){
this.items=[
{
title: 'Tab 1',
html: 'A simple tab'
},{
title: 'Tab 2',
html: 'Another one'
}
]
TeEE.superclass.constructor.call(this, config);
}
Ext.extend(TeEE,TestExtend,{})[/code]
在上面的代码中,每个 TeEE 的实例都有一个 items 属性,且他们之间是没有任何关系的,也就是说不是引用的同一个东西
另外,原先你的写法语法上是没有任何问题的,只不过是“设计得不好”。发现错误了,你应该调试一下,看看具体是什么原因