defreq
basic require define functionality, built for use with an private SPA, where modules could only be required once for secruity and seperation of code.
Features:
- Modules are defined with the keyword
define
// optional parameters 'dep1', 'dep2', 'depN' are injected dependencies
// optional parameter 'multiple' (bool) allows multiple instantiations
define(id, function(dep1, dep2, depN...) {
// The module code goes here
}, multiple);
- Modules are created with the keyword
require
// optional parameters 'dep1', 'dep2', 'depN' are the dependencies
var mod = require(id, dep1, dep2, depN...);
var mod = require(id);
- It is not a loader, so files will need to be loaded
- Modules are not singletons
Sample Code
a.js
define('a', function(jq){
function name(){
return jq.trim('I am a');
}
return {
name: name
}
});
main.js
var a = require('a', $);