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

标签 javascript dojo amd

Dojo 表示“dojo AMD 格式,使代码更易于编写和调试” (https://dojotoolkit.org/documentation/tutorials/1.10/modules_advanced/)

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

最佳答案

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

  • 组织:当您从模块的 Angular 思考时,您的代码往往会更加结构化和有组织。
  • 调试:由于每个模块的功能/特性是分开的,因此可以简化调试,因为模块的代码量在长度和范围上受到更多限制。
  • 测试:当您的代码在单独的模块中得到明确定义时,组织测试用例会更容易。

有关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
    });
});

关于javascript - "dojo AMD format, makes code easier to author and debug",如何证明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43730359/

相关文章:

JavaScript 范围 : How to create anonymous functions with different values?

javascript - 使用 "this"的 javascript dojo 闭包中使用的函数 -notation 未定义

javascript - RequireJS 管理大型模块

javascript - Dojo AMD 加载器是否确保模块只执行一次?

module - 使用 Angular JS 时如何加载 AMD 模块?

javascript - 从php页面获取JSON数据

javascript - 某个事件过去了多少时间

javascript - 如何取消选中 Framework7 中的自定义设计单选按钮?

javascript - Dojo 小部件 ID 已注册

javascript - Google Sheet 脚本中的正则表达式