这不是一个特别长的模块列表。 Dojo将其功能分解为相当小的模块,因此很多时候都会提取其中的很多模块。
你肯定不希望在回调中要求他们。 define
与require
基本相同,但在模块的顶部用于声明具有依赖关系的异步模块的结果。
有一件值得注意的事情是,可能值得向具有相同或相似名称的参数注入类依赖关系:它使结果declare
调用更简单,例如,
define(["dojo/_base/declare", "dijit/_WidgetBase", "dijit/_TemplatedMixin", "dojo/text!mytemplate.html"], function(declare, _WidgetBase, _TemplatedMixin, template) {
return declare("my.Widget", [_WidgetBase, _TemplatedMixin], {
templateString: template
};
});
您也可能希望将您的依赖关系组合为逻辑组,例如,把你的基类放在一起,将辅助模块放在一起。您还需要声明模板中提到的其他模块,位于模块列表的端,如果您未在代码中使用它们,则不一定需要将它们声明为回调参数,例如used/by/template1
and used/by/template2
here:
define(["dojo/_base/declare", "dijit/_WidgetBase", "dijit/_TemplatedMixin", "dojo/text!mytemplate.html", "used/by/template1", "used/by/template2"], function(declare, _WidgetBase, _TemplatedMixin, template) {
return declare("my.Widget", [_WidgetBase, _TemplatedMixin], {
templateString: template
};
});