1

尝试扩展小部件时遇到问题,给我错误:

声明 ImageBoxAnim:使用继承调用链式构造函数

我没能找到有同样问题的人,所以我认为这是我对dojo/_base/declare.

基类“_ImageBoxBase”(极其简化):

define(['dojo/_base/declare', 'dijit/_WidgetBase'], function(declare, _WidgetBase){
    return declare('_ImageBoxBase', [_WidgetBase], {
        constructor : function(){...}
    }
})

ImageBox(_ImageBoxBase 的子类 1):

define(['dojo/_base/declare', './_ImageBoxBase'], function(declare, _ImageBoxBase){
    return declare("ImageBox", [_ImageBoxBase], {
        constructor : function(){
            this.inherited(arguments)
            // this class works like a charm
        }
    }
})

ImageBoxAnim(ImageBox 的子类):

define(['dojo/_base/declare', './ImageBox'], function(declare, ImageBox){
    return declare("ImageBoxAnim", [ImageBox], {
        constructor : function(){
            this.inherited(arguments)
            // no worky!
        }
    }
})

我已经用 declare 语句尝试了很多变体,唯一至少允许脚本不抛出错误的是一个空的“父”类,但它并没有 widgitify。它会按原样呈现 HTML/CSS,但在返回的declare对象中不会调用任何方法。

Essentially there's functionality in the ImageBox class I'd like ImageBoxAnim to inherit, while adding more functionality (animations).

The thing that gets me is when defining the ImageBox class, it's the same syntax and, I thought, the same process to extend _WidgetBase as it is to extend something that extends _WidgetBase. A lot of online examples give ways to extend built-in dijits, so I don't see where I'm going wrong.

Note: I know these aren't technically "classes", but from an extending/sub/superclass point of view, it's easier to verbalize.

4

1 回答 1

3

I can't be sure, but I imagine you're seeing problems because constructors are automatically chained (no need to call this.inherited). If you want to chain manually, check out manual constructor chaining

于 2013-02-07T20:41:19.607 回答