2013-02-07 31 views
1

我試圖擴展插件時的問題,給我的錯誤:擴展自定義的dijit「鏈構造」錯誤

declare ImageBoxAnim: calling chained constructor with inherited

我是在用同樣的問題找到任何不成功的,所以我想這是我的當涉及到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對象中調用NO方法。

本質上有ImageBox類中的功能我希望ImageBoxAnim繼承,同時添加更多的功能(動畫)。

得到我的東西是在定義ImageBox類時,它的語法和我想的是相同的過程來擴展_WidgetBase,因爲它擴展了一些擴展了_WidgetBase的東西。很多在線示例都提供了擴展內置的dijits的方法,所以我不知道我哪裏會出錯。

注意:我知道這些在技術上不是「類」,但從擴展/子類/超類的角度來看,它更容易表達。

回答

3

我不能確定,但​​我想你會看到問題,因爲構造函數被自動鏈接(不需要調用this.inherited)。如果你想手動鏈接,看看manual constructor chaining

+1

這就是我曾經想過的。然而,即使拿出繼承的調用,甚至進一步取出所有的構造函數,postCreate等調用它仍然拋出。我會盡力把小提琴或測試頁放在一起。 – Phix

+0

我不確定我做了什麼,可能有點愚蠢,但我的其他dijits按預期運行。我會重溫。 – Phix