UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

37 lines (36 loc) 1.67 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const CONSTANTS_1 = require("./CONSTANTS"); const createCtor_1 = __importDefault(require("./createCtor")); const apply_1 = __importDefault(require("./apply")); const root_1 = __importDefault(require("./root")); /** * Creates a function that wraps `func` to invoke it with the `this` binding * of `thisArg` and `partials` prepended to the arguments it receives. * * @private * @param {Function} func The function to wrap. * @param {number} bitmask The bitmask flags. See `createWrap` for more details. * @param {*} thisArg The `this` binding of `func`. * @param {Array} partials The arguments to prepend to those provided to * the new function. * @returns {Function} Returns the new wrapped function. */ function createPartial(func, bitmask, thisArg, partials) { var isBind = bitmask & CONSTANTS_1.WRAP_BIND_FLAG, Ctor = (0, createCtor_1.default)(func); function wrapper() { var argsIndex = -1, argsLength = arguments.length, leftIndex = -1, leftLength = partials.length, args = Array(leftLength + argsLength), fn = (this && this !== root_1.default && this instanceof wrapper) ? Ctor : func; while (++leftIndex < leftLength) { args[leftIndex] = partials[leftIndex]; } while (argsLength--) { args[leftIndex++] = arguments[++argsIndex]; } return (0, apply_1.default)(fn, isBind ? thisArg : this, args); } return wrapper; } exports.default = createPartial;