0

我有一个叫做的小部件,stat.widget.Weekly它是一个_Container,但每当我使用时,我都会得到requirestat.widget.DailyDailynew Daily()

Uncaught TypeError: undefined is not a function

我的代码是这样的

require([
 "dojo/_base/declare", "dojo/parser", ..., "stat/widget/Daily", "dijit/_Container"
 ], function(declare, ... , _WidgetBase, _TemplatedMixin, Daily, _Container){
     declare("stat.widget.Weekly", [_WidgetBase, _TemplatedMixin, _Container], {
        ....
        update: function(){
            new Daily();//< Fires Error
        },
        postCreate: function(){
            var self = this;
            setTimeout(function(){
              self.update();
            }, 500);            
        }
     });
 });

但这stat/widget/Daily可以在控制台中实例化new

4

1 回答 1

0

如果您的 stat.widget.Weekly 放在 stat-Modulepath/widget/Daily.js 下的文件中,则此语法在类加载器中处理起来会更流畅:

define([ // using define instead of require
 "dojo/_base/declare", "dojo/parser", ..., "stat/widget/Daily", "dijit/_Container"
 ], function(declare, ... , _WidgetBase, _TemplatedMixin, Daily, _Container){

 var myPrivates = declare("stat.widget._WeeklyResource", [], {
     ...
 });
 var myDefinition = declare("stat.widget.Weekly", [_WidgetBase, _TemplatedMixin, _Container], {
     ...
 });
 // returning the definition
 return myDefinition;

});

于 2012-05-30T11:13:13.710 回答