"dojo AMD format, makes code easier to author and debug",如何证明呢?

"dojo AMD format, makes code easier to author and debug", how to prove it?

Dojo 说 "dojo AMD format, makes code easier to author and debug" (https://dojotoolkit.org/documentation/tutorials/1.10/modules_advanced/)

有没有人可以给我们看一个示例代码来证明这个说法? 坦克:)

AMD 允许 division/organization 模块中的代码按需加载,这有一些优点:

  • 组织:当您从模块的角度考虑时,您的代码往往更有条理和更有条理。
  • 调试:由于您的代码在每个模块 functionalities/feature 中分开,因此简化了调试,因为模块的代码量在长度和范围上受到更多限制。
  • 测试:当您的代码在单独的模块中得到明确定义时,组织测试用例会更容易。

有关 AMD and module 的更多信息。

导航栏的简单模块示例:

// in "my/widget/NavBar.js"
define([
    "dojo/_base/declare",
    "dijit/_WidgetBase",
    "dijit/_TemplatedMixin",
    "dojo/text!./templates/NavBar.html"
], function(declare, _WidgetBase, _TemplatedMixin, template){
    return declare([_WidgetBase, _TemplatedMixin], {
        // template contains the content of the file "my/widget/templates/NavBar.html"
        templateString: template
    });
});