require.js 订购插件并定义
Define() 如何处理传统的 javascript 文件?
例如,
a.js
define(['b', 'c.js', 'd.js'], function(b){ /* code */});
c.js 或 d.js 何时获取并加载?它会在 function(b){} 中加载并可用吗?
我知道订单没有保留。订单插件对此有帮助吗?
文档说
使用define()定义模块的脚本不需要
,但这也适用于传统脚本吗?
谢谢
How does define() treat traditional javascript files?
For example,
a.js
define(['b', 'c.js', 'd.js'], function(b){ /* code */});
When does c.js or d.js get fetched and loaded? Will it be loaded and available in function(b){}?
I know that the order is not preserved. Will the order plugin help for this?
The docs say
It is not needed for scripts that use define() to define modules
but does that apply to traditional scripts as well?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于没有定义模块的普通 Javascript 文件,它们将以任意顺序加载和执行。在上面的示例中,不能保证
c.js
将在d.js
之前执行。但是当你的回调执行时,两者都会被加载。如果您需要
c.js
和d.js
按顺序执行,请使用 order 插件。For plain Javascript files that do not define modules, they will be loaded and executed in arbitrary order. In your example above, there's no guarantee that
c.js
will execute befored.js
. But by the time your callback executes, both will be loaded.If you need
c.js
andd.js
to execute in order, use the order plugin.