2013-03-24 124 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設置並演示解決方案。