gpt4 book ai didi

dojo - 更新 Dojo 提供

转载 作者:行者123 更新时间:2023-12-04 04:37:25 24 4
gpt4 key购买 nike

我正在为一个项目使用 Dojo 1.9,但我不明白 dojo.provide 的正确替代方案与传统风格相比,AMD 风格。我正在阅读 this文档页面。

很明显,这就是旧语法映射到新语法的方式:


dojo.provide("acme.Dialog");
dojo.require("dijit._Widget");
dojo.require("dojo.date");
CODE HERE


define(["dijit/_Widget", "dojo/date"], function(_Widget, date){   ....
CODE HERE
return MyWidget;
});

我不确定我作为 MyWidget 返回的究竟是什么。我的代码看起来像这样:
define(["dojo/foo/x","dojo/foo/y"], function(x, y){
dojo.provide("my.module");
});

我应该回到这里做什么?

最佳答案

这是一个非常棒的教程,“现代道场”:

http://dojotoolkit.org/documentation/tutorials/1.7/modern_dojo/

好的报价:

If you find yourself typing dojo.* or dijit.* or dojox.*, something isn't right.



更改 AMD 的基本原理:

One of the core concepts of "modern" Dojo is that things in the global namespace are bad. There are numerous reasons for this, but in a complex web application, the global namespace can easily become polluted with all manner of code, especially when a lot of organisations use multiple JavaScript frameworks. I won't even mention the nefarious things that can happen from a security standpoint with people intentionally modifying the global namespace. This means in "modern" Dojo, if you are about to access something in the global namespace STOP because you are doing something wrong.

...

Another core concept is that synchronous operations are slow and asynchronous ones are usually faster. "Legacy" Dojo already had a fairly strong pedigree in asynchronous JavaScript code with the concept of dojo.Deferred, but in "modern" Dojo, it is best to think of everything operating asynchronously.

...

To strengthen the modularity of Dojo and leverage the concepts above, in 1.7 Dojo adopted the CommonJS module definition called Asynchronous Module Definition (AMD). This meant a fundamental re-write of the Dojo module loader which is usually exposed through the require() and define() functions. You can find full documentation of the loader in the reference guide.. This has fundementally changed the way code is structured.

关于dojo - 更新 Dojo 提供,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19504147/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com