" dojo AMD格式,使代码更容易编写和调试",如何证明它?

时间:2017-05-02 04:57:44

标签: javascript dojo amd

Dojo说" dojo AMD格式,使代码更容易编写和调试" (https://dojotoolkit.org/documentation/tutorials/1.10/modules_advanced/

有没有人可以向我们展示一个示例代码来证明这个陈述? 坦克:)

1 个答案:

答案 0 :(得分:1)

AMD允许在模块中划分/组织代码,这些模块按需加载,这有一些优点:

  • 组织:当您考虑模块时,您的代码往往更加结构化和有条理。
  • 调试:由于代码在每个模块的功能/特性中是分开的,因此简化了调试,因为模块的代码量在长度和范围上更加有限。
  • 测试:当您的代码在单独的模块中定义良好时,组织测试用例会更容易。

有关basic privacy policy template here的更多信息。

导航栏的简单模块示例:

// 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
    });
});
相关问题