Javascript Extjs多重继承?

Javascript Extjs多重继承?,javascript,inheritance,extjs,gridpanel,Javascript,Inheritance,Extjs,Gridpanel,我有一个关于ExtJS中多重继承的问题。虽然我知道我可以简单地复制代码来实现它,但我想知道是否有任何方法可以更有效地编写代码 我的框架中有一个定制的GridPanel组件,名为Kore.ux.grid.GridPanel。它扩展了Ext.GridPanel,具有额外的通用功能,并为REST操作提供了接口 不久之后,我的同事想让EditorGridPanel也以同样的方式实现,也就是说,她希望它是可编辑的,同时能够轻松地执行REST操作 我的问题是,是否有任何方法可以扩展Ext.EditorGri

我有一个关于ExtJS中多重继承的问题。虽然我知道我可以简单地复制代码来实现它,但我想知道是否有任何方法可以更有效地编写代码

我的框架中有一个定制的
GridPanel
组件,名为
Kore.ux.grid.GridPanel
。它扩展了
Ext.GridPanel
,具有额外的通用功能,并为REST操作提供了接口

不久之后,我的同事想让
EditorGridPanel
也以同样的方式实现,也就是说,她希望它是可编辑的,同时能够轻松地执行REST操作

我的问题是,是否有任何方法可以扩展
Ext.EditorGridPanel
来使用定制的
Kore.ux.grid.GridPanel
功能

对不起,有语法错误,如果让人困惑,我可以重新措辞。谢谢

编辑

我又在谷歌上搜索了一遍,发现有帖子说这是不可能的。有没有更好的编码模式,我应该遵循,如果我有这个问题

谢谢

再次编辑

很抱歉我找到了适合我的结构。。以下是我发现对我有用的方法:

var Common = function(){}   //abstract class
Ext.apply(Common.prototype, {

    a : function(){},
    b: function(){}...

});

Ext.ux.SomePanelA = Ext.extend ( Ext.Panel, {

    stuff : ............

});

Ext.ux.SomePanelB = Ext.extend ( Ext.Panel, {

    diffStuff : ............

});

Ext.applyIf(Ext.ux.SomePanelA.prototype, Common.prototype);
Ext.apply(Ext.ux.SomePanelB.prototype, Common.prototype);
代码来源:


如果您认为您有更好的解决方案,请再次提供有用的建议:)谢谢

创建
Kore.ux.grid.AbstractGridPanel
作为具有一般功能的基类。并创建两个子类:
Kore.ux.grid.GridPanel
Kore.ux.grid.EditorGridPanel
(具有特定功能)。

您真正需要研究的是ExtJS插件

/**
 * Boilerplate code taken from 'ExtJS in Action' by Jay Garcia
 */
YourNameSpace.RestGridPlugin = Ext.extend(Object, {
  constructor : function(config) {
    config = config || {};
    Ext.apply(this.config);
  },

  init : function(parent) { //parent argument here, is whatever you apply your plugin to
    parent.on('destroy', this.onDestroy, this);
    Ext.apply(parent, this.parentOverrides);
  },

  onDestroy : function() {
    //here you need to free any resources created by this plugin
  },

  parentOverrides : {
    //here you do your magic (add functionality to GridPanel)
  }

});

Ext.preg('restgridplugin',YourNameSpace.RestGridPlugin); //register your brand ne plugin
用法


我不同意使用插件在Ext中完成多重继承。插件旨在改变行为或添加新功能

实现多重继承的正确方法是使用mixin,请看这个惊人的解释


问题是,
Ext.grid.EditorGridPanel
扩展了
Ext.grid.GridPanel
,我提供的其余“接口”是扩展
Ext.grid.GridPanel
,因为我需要在
Ext.grid.EditorGridPanel
中提供的功能,我认为最好的方法是编写一个公共基类,并使用公共基类扩展
Ext.grid.GridPanel
Ext.grid.EditorGridPanel
。谢谢你的输入:)插件!为什么我忘记了它的存在!!谢谢你的建议:)看看我将如何将其纳入框架。谢谢:)但这可能不适合我的情况,因为我的自定义GridPanel提供了自定义分页工具栏、预定义按钮、搜索框、REST。。。等插件可能不是这样:)无论如何谢谢你的建议!为什么不呢?您可以从插件中访问这些自定义组件,以便将您的功能绑定到它们。毕竟,这个插件实际上是按照您现在的方式来做的。它只是增加了一个更加健壮和易于使用的API。是的,我认为你的应该是答案,因为这是我应该说的最干净的方式。如果有什么不对劲,我就把它放在这里!。感谢您的输入:)
someGrid = {
  xtype: 'grid',
  columns: ...
  store: ...
  plugins: [
    'restgridplugin'
  ]
}

someEditorGrid = {
  xtype: 'editorgrid',
  columns: ...
  store: ...
  plugins: [
    'restgridplugin'
  ]
}
 Ext.define('FunctionalityA', {
     methodA: function () {
         ...
     }
 });

 Ext.define('FunctionalityB', {
     methodB: function () {

     }
 });

 Ext.define('MultipleFunctionality', {
     mixins: [
         'FunctionalityA',
         'FunctionalityB'
     ],

     method: function () {
         methodA();
         methodB();
     }
 });