mixin.js 543 B

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