-
-
Save jboesch/641505 to your computer and use it in GitHub Desktop.
// 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); | |
}); | |
} | |
} | |
}); |
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 :/
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
should that be
require.def
?