2013-03-24 126 views
2

我有一个Base类继承[_WidgetBase, _TemplatedMixin]Base正常工作。现在,我继承了这个Base在另一类是不工作Dijit构造函数抛出“调用链式构造函数”错误

define([ 
    "dojo/_base/declare", "dojo/parser", ... 
], function(declare, parser, ...){ 
    return declare("mc.widgets.Base", [_WidgetBase, _TemplatedMixin], { 
     templateString: 
      '<div class="mc-note-base">'+ 
      '</div>', 
     constructor: function(argv){ 
      var self = this.inherited(arguments); 
      return self; 
     }, 
     data: function(){ 

     }, 
     postCreate: function(){ 
      ... 
     } 
    }) 
}); 

派生类

define([ 
    "dojo/_base/declare", "mc/base/path", "mc/widgets/Base" 
], function(declare, path, Base){ 
    return declare("mc.widgets.Derived", [Base], {}); 
}) 

派生类抛出

Error: declare mc.widgets.Derived: calling chained constructor with inherited

回答

2

发生这种情况,因为Widget的生命周期的constructor部分用特殊的链接机制处理,为更灵活的Widget创建而设计。您可以read here更多的信息,而是适用于您的情况的部分说:

Superclass constructors are always called automatically, and always before the subclass constructor. This convention reduces boilerplate in 90% of cases. If it doesn’t fit your needs see Manual Constructor Chaining below. For all other methods, use this.inherited(arguments) to call the superclass method of the same name.

如果你只是删除您Widget的构造方法this.inherited(arguments)电话,您的问题将得到解决。 Here is a simple jsfiddle模仿您的Widget设置并演示解决方案。