nic*_*ckf 9 javascript module amd requirejs
我正在为使用RequireJS的应用程序编写一些测试.由于应用程序的工作方式,它希望通过调用获得一些类require.因此,对于测试,我有一些虚拟类,但我不想将它们放入单个文件中,仅用于此测试.我更喜欢define()在我的测试文件中手动设置它们,如下所示:
define('test/foo', function () {
return "foo";
});
define('test/bar', function () {
return "bar";
});
test("...", function () {
MyApp.load("test/foo"); // <-- internally, it calls require('test/foo')
});
Run Code Online (Sandbox Code Playgroud)
这里的问题是这些模块的评估被推迟,直到脚本onload事件被触发.
Run Code Online (Sandbox Code Playgroud)//Always save off evaluating the def call until the script onload handler. //This allows multiple modules to be in a file without prematurely //tracing dependencies, and allows for anonymous module support, //where the module name is not known until the script onload event //occurs. If no context, use the global queue, and get it processed //in the onscript load callback. (context ? context.defQueue : globalDefQueue).push([name, deps, callback]);
有什么方法可以手动触发要评估的队列吗?