mixin.js 620 B

123456789101112131415161718192021
  1. var underscore = require('./underscore.js');
  2. var each = require('./each.js');
  3. var functions = require('./functions.js');
  4. var _setup = require('./_setup.js');
  5. var _chainResult = require('./_chainResult.js');
  6. // Add your own custom functions to the Underscore object.
  7. function mixin(obj) {
  8. each(functions(obj), function(name) {
  9. var func = underscore[name] = obj[name];
  10. underscore.prototype[name] = function() {
  11. var args = [this._wrapped];
  12. _setup.push.apply(args, arguments);
  13. return _chainResult(this, func.apply(underscore, args));
  14. };
  15. });
  16. return underscore;
  17. }
  18. module.exports = mixin;