Dojo切面继承

Dojo aspect inheritance

我在 dojo 方面以及它如何处理继承时遇到问题。

我 class 叫 child1,另一个 class 叫 child2。 class 都继承自 parent.

孩子 1:

return declare("child1", [parent], ...

孩子 2:

return declare("child2", [parent], ...

Child1 和 Child2 的实现有很大不同。 Parent 有一个 child1 需要方面的方法:

this.own(aspect.before(this, "_onChange", lang.hitch(this, "_onRowSelected"), true));

在调用 child1 之前,child2 一切正常。 那时,无论何时从 Parent 调用 _onChange 方法,函数 child1._onRowSelected 都是 运行...无论调用来自何处。

我认为方面只会涉及在 child1 中创建方面调用的 object,而不会影响 child2。

我唯一能想到的是,看起来 child1 和 child2 的实例化是在 HTML 模板中完成的。

如果使用继承,为什么要使用aspect? 在这种情况下是没有必要的。

Child1 中,只需创建一个方法 _onChange,如下所示:

_onChange: function() {
    this._onRowSelected();
    this.inherited(arguments);
}

不需要aspect

就可以达到同样的效果