_partial.js 782 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. var path = require('./_path');
  3. var invoke = require('./_invoke');
  4. var aFunction = require('./_a-function');
  5. module.exports = function (/* ...pargs */) {
  6. var fn = aFunction(this);
  7. var length = arguments.length;
  8. var pargs = new Array(length);
  9. var i = 0;
  10. var _ = path._;
  11. var holder = false;
  12. while (length > i) if ((pargs[i] = arguments[i++]) === _) holder = true;
  13. return function (/* ...args */) {
  14. var that = this;
  15. var aLen = arguments.length;
  16. var j = 0;
  17. var k = 0;
  18. var args;
  19. if (!holder && !aLen) return invoke(fn, pargs, that);
  20. args = pargs.slice();
  21. if (holder) for (;length > j; j++) if (args[j] === _) args[j] = arguments[k++];
  22. while (aLen > k) args.push(arguments[k++]);
  23. return invoke(fn, args, that);
  24. };
  25. };