Skip to content

Instantly share code, notes, and snippets.

@kriskowal
Forked from tobie/gist:339643
Created March 21, 2010 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kriskowal/339654 to your computer and use it in GitHub Desktop.
Save kriskowal/339654 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;
};
}
}
});
var eventualTwo = Q.when(require.async('increment'), function(mod) {
var inc = mod.increment;
var a = 1;
return inc(a) // 2
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment