有几种方法可以做到:
- 坚持使用一个版本的 Dojo 并始终如一地使用它。
- 将修改后的代码移动到您自己的命名空间并从那里包含它。
- 实际上,它是现有 DojoX 模块的一个分支。所有代码同步和反向移植都是您的责任。
- 注意 Dojo 的其余部分——如果它的变化导致你的分叉版本被破坏,那么也要准备好修补你的模块。
- 将修改后的文件复制到某处并在需要原始文件之前包含/需要它们。
为了说明后一种技术,假设我要修补位于 dojox/charting/abc.js 中的一个文件:
dojo.provide("dojox.charting.abc");
// the rest of the file
...
我可以将它复制到我的目录中,例如 my/patched_abc.js,并使其看起来像这样:
dojo.provide("my.patched_abc");
// now I include the rest of the file with my modifications
dojo.provide("dojox.charting.abc");
// the rest of the file
...
在我使用 dojox.charting 的代码中,我像这样包含它:
dojo.require("my.patched_abc");
// now I can include dojox.charting,
// which will use my patched dojox.charting.abc module
dojo.require("dojox.charting.Chart2D");
// the rest of the file
...
请注意避免循环“要求”语句。
这种技术非常适用于反向移植和小型定制。如果您的更改比这更广泛,您应该考虑编写自己的模块。