“dojo AMD格式,让代码更容易创作和调试”,如何证明?[已关闭]

myzjeezk  于 2022-12-16  发布在  Dojo
关注(0)|答案(1)|浏览(134)

已关闭。此问题需要超过focused。当前不接受答案。
**想要改进此问题吗?**更新此问题,使其仅关注editing this post的一个问题。

5年前关闭。
Improve this question
Dojo表示“dojo AMD格式,使代码更容易创作和调试”(https://dojotoolkit.org/documentation/tutorials/1.10/modules_advanced/
有没有人可以给我们一个例子来证明这个说法?坦克:)

xmd2e60i

xmd2e60i1#

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

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

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

相关问题