【问题标题】:Inheritance of Delegate委托的继承
【发布时间】:2018-01-22 10:20:42
【问题描述】:

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

知道我想添加这些类的一些子元素并将一些项目添加到列表中。现在我必须通过调用 configureItem 中的函数来调整configureItem。这个函数检查项目是否在当前类中,如果不是,我调用处理他的项目标签的超类方法。

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

这里有一些代码 sn-ps:

//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);
}

有人可以帮我解决这个问题还是有更好的方法来解决我的问题?

【问题讨论】:

  • 错误是指arguments.caller 和arguments.callee 在严格模式下不可用(Qooxdoo 6 应用程序使用),您的 sn-p 不使用它,所以我需要更多信息。请您在操场上提供一个工作示例(qooxdoo.org/current/playground)?

标签: inheritance qooxdoo


【解决方案1】:

问题在于编译器仅支持this.base,而您将this 别名为that,因此无法识别。

我已在此处添加此问题 (https://github.com/qooxdoo/qooxdoo-compiler/issues/102),并且需要在我们发布 6.0 之前修复该特定问题。

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

但是,如果您不能只更改为使用 this.base,则解决方法是使用显式方法调用,例如,您可以使用类似

的东西而不是 that.base
operatorDelegateItems : function(item, that) {
    if (item.getLabel() == "Period")
        item.setLabel("Jahresintervall");
    else
        myapp.MyBaseClass.prototype.operatorDelegateItems.call(this, item, that);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-12
    • 2017-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-18
    相关资源
    最近更新 更多