Skip to content

Instantly share code, notes, and snippets.

@tobie
Created March 21, 2010 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tobie/339643 to your computer and use it in GitHub Desktop.
Save tobie/339643 to your computer and use it in GitHub Desktop.
require.def({
'increment': {
'requires': ['math'],
'factory': function() {
var exports = arguments[0].exports,
require = arguments[0].require,
module = arguments[0].module;
var add = require('math').add;
exports.increment = function(val) {
return add(val, 1);
};
}
},
'math': {
'requires': [],
'factory': function() {
var exports = arguments[0].exports,
require = arguments[0].require,
module = arguments[0].module;
var add = require('math').add;
exports.add = function() {
var sum = arguments[0];
for (var i=1; i<arguments.length; i++) {
sum += arguments[i];
}
return sum;
};
}
}
});
require.async('increment', function(mod) {
var inc = mod.increment;
var a = 1;
inc(a); // 2
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment