Created
October 22, 2010 22:35
-
-
Save jboesch/641505 to your computer and use it in GitHub Desktop.
requireJS dependencies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using http://requirejs.org/ | |
// loading scripts/misc/person.js | |
require(["misc/person"], function(person) { | |
person.loaded(function(){ | |
alert('dependencies loaded!'); | |
// dependencies loaded, now do something with person | |
}); | |
}); | |
// Inside scripts/misc/person.js | |
define(function(){ | |
var dependencies = [ | |
'helper/ear', // looking to scripts/helper/ear.js | |
'helper/nose', | |
'helper/eyes' | |
]; | |
return { | |
loaded: function(cb){ | |
require(dependencies, function(){ | |
cb.apply(this, arguments); | |
}); | |
} | |
} | |
}); |
oh, good to know. Doesn't it take a string as the first argument, or are you using the file location to define the module name?
Yeah I'm just using the file location as the module name. I figured I'd just save some chars
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Apparently it's recently been changed - http://requirejs.org/docs/api.html:
"NOTE: As of RequireJS 0.14.3, the function define() is preferred to create modules. Previously it was require.def(). require.def is still available, but define() is encouraged in the interests of conforming to the Asynchronous Module Proposal. You are free to continue require.def() if you only want RequireJS to load the modules, but if you want your code to be potentially interoperable with other Async Module script loaders, you should consider using define(). Any API examples that use define() will work the same if require.def() is used instead."
..I don't really plan on using this code with any other Async Module script loaders... just thought I'd do it if it's preferred :/