http://dojotoolkit.org/reference-guide/loader/amd.html#generic-script-injection

When I'm using require() to do generic script injection, is there any way I can pass the injected script values without having to rely on globals?

有帮助吗?

解决方案

Usually in Dojo land, when you require() in something, you are requiring a class, and then when you instantiate the class, you pass in constructor args.

You could use the addOnLoad callback to apply values as you want, if you just want access to generic Javascript:

dojo.require("my.awesome.code");
dojo.addOnLoad(function(){
   // Do something groundbreaking with my.awesome.code
});

Or in Dojo > 1.7 (AMD loader):

require(["dojo/ready", "my/awesome/code"], function(ready, code){
     // Do something groundbreaking with my.awesome.code
});

Take a look here for more info: dojo.require Overview

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top