委托的继承

Inheritance of Delegate

我创建了一个带有选择框和一些列表项的 Class。要更改这些项目的标签,我将选择框控制器的委托设置为 configureItem

知道我想添加这些 class 的一些子元素并向列表添加一些项目。现在我必须通过调用 configureItem 中的函数来调整 configureItem。此函数检查 Item 是否在当前 class 中,如果不在,我调用 superclass 方法来处理他的 Items.

Qooxdoo 5.0.2 运行良好。现在我更改为 Qooxdoo 6 以使用新的编译器,但在调用 Superclass 方法时出现错误:Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them

以下是一些代码片段:

//Set Delegate in superclass
this.operatorController.setDelegate({
    configureItem : function(item) {
        that.operatorDelegateItems(item, that);
    }
});

// Superclass Method
operatorDelegateItems : function(item, that) {
        switch (item.getLabel()) {
        case "":
            item.setLabel(qx.locale.Manager.tr("Ist Vorhanden"));
            break;
        case "-":
            item.setLabel(qx.locale.Manager.tr("Ist nicht Vorhanden"));
            break;
        case "Nachfolger":
            item.setLabel(qx.locale.Manager.tr("Zeige Nachfolger"));
            break;
        }
    }

// Child class Delegate FUnction
operatorDelegateItems : function(item, that) {
    if (item.getLabel() == "Period")
        item.setLabel("Jahresintervall");
    else
        that.base(arguments, item);
}

有人可以帮我解决这个问题,或者有更好的方法来解决我的问题吗?

问题是编译器只支持 this.base 并且您将 this 别名为 that 因此无法识别。

我已将此作为问题添加到此处 (https://github.com/qooxdoo/qooxdoo-compiler/issues/102),该特定问题需要在我们发布 6.0 之前解决。

查看您的代码,解决方法是不需要在 that 变量中携带 this,因此将您的代码更改为 this.base 可行(感谢您的尝试)在 Gitter qooxdoo!)

但是,如果您不能仅更改为使用 this.base,解决方法是使用显式方法调用,例如您可以使用 [= 而不是 that.base 21=]

operatorDelegateItems : function(item, that) {
    if (item.getLabel() == "Period")
        item.setLabel("Jahresintervall");
    else
        myapp.MyBaseClass.prototype.operatorDelegateItems.call(this, item, that);
}