MCPcopy
hub / github.com/lodash/lodash / createWrap

Function createWrap

lodash.js:5581–5634  ·  view source on GitHub ↗

* Creates a function that either curries or invokes `func` with optional * `this` binding and partially applied arguments. * * @private * @param {Function|string} func The function or method name to wrap. * @param {number} bitmask The bitmask flags. * 1 - `_.bind`

(func, bitmask, thisArg, partials, holders, argPos, ary, arity)

Source from the content-addressed store, hash-verified

5579 * @returns {Function} Returns the new wrapped function.
5580 */
5581 function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
5582 var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
5583 if (!isBindKey && typeof func != 'function') {
5584 throw new TypeError(FUNC_ERROR_TEXT);
5585 }
5586 var length = partials ? partials.length : 0;
5587 if (!length) {
5588 bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
5589 partials = holders = undefined;
5590 }
5591 ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
5592 arity = arity === undefined ? arity : toInteger(arity);
5593 length -= holders ? holders.length : 0;
5594
5595 if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
5596 var partialsRight = partials,
5597 holdersRight = holders;
5598
5599 partials = holders = undefined;
5600 }
5601 var data = isBindKey ? undefined : getData(func);
5602
5603 var newData = [
5604 func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
5605 argPos, ary, arity
5606 ];
5607
5608 if (data) {
5609 mergeData(newData, data);
5610 }
5611 func = newData[0];
5612 bitmask = newData[1];
5613 thisArg = newData[2];
5614 partials = newData[3];
5615 holders = newData[4];
5616 arity = newData[9] = newData[9] === undefined
5617 ? (isBindKey ? 0 : func.length)
5618 : nativeMax(newData[9] - length, 0);
5619
5620 if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
5621 bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
5622 }
5623 if (!bitmask || bitmask == WRAP_BIND_FLAG) {
5624 var result = createBind(func, bitmask, thisArg);
5625 } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
5626 result = createCurry(func, bitmask, arity);
5627 } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
5628 result = createPartial(func, bitmask, thisArg, partials);
5629 } else {
5630 result = createHybrid.apply(undefined, newData);
5631 }
5632 var setter = data ? baseSetData : setData;
5633 return setWrapToString(setter(result, newData), func, bitmask);
5634 }
5635
5636 /**
5637 * Used by `_.defaults` to customize its `_.assignIn` use to assign properties

Callers 5

aryFunction · 0.85
lodash.jsFile · 0.85
curryFunction · 0.85
curryRightFunction · 0.85
flipFunction · 0.85

Calls 6

toIntegerFunction · 0.85
mergeDataFunction · 0.85
createBindFunction · 0.85
createCurryFunction · 0.85
createPartialFunction · 0.85
setWrapToStringFunction · 0.85

Tested by

no test coverage detected