Sha256: 229faccb2beb1c287454a5c6f825c63393840d72bba5f7d80c29aa2f604abfb6

Contents?: true

Size: 1.35 KB

Versions: 270

Compression:

Stored size: 1.35 KB

Contents

var apply = require('./_apply'),
    createCtor = require('./_createCtor'),
    root = require('./_root');

/** Used to compose bitmasks for function metadata. */
var WRAP_BIND_FLAG = 1;

/**
 * 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 & WRAP_BIND_FLAG,
      Ctor = createCtor(func);

  function wrapper() {
    var argsIndex = -1,
        argsLength = arguments.length,
        leftIndex = -1,
        leftLength = partials.length,
        args = Array(leftLength + argsLength),
        fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;

    while (++leftIndex < leftLength) {
      args[leftIndex] = partials[leftIndex];
    }
    while (argsLength--) {
      args[leftIndex++] = arguments[++argsIndex];
    }
    return apply(fn, isBind ? thisArg : this, args);
  }
  return wrapper;
}

module.exports = createPartial;

Version data entries

270 entries across 269 versions & 28 rubygems

Version Path
govuk_publishing_components-16.19.0 node_modules/lodash/_createPartial.js
govuk_publishing_components-16.18.0 node_modules/lodash/_createPartial.js
govuk_publishing_components-16.17.0 node_modules/lodash/_createPartial.js
blsk-sevcore-0.0.2 blsk_old/bluesky-doc/bluesky-doc/node_modules/lodash/_createPartial.js
ela-4.1.6 node_modules/lodash/_createPartial.js
ela-4.1.5 node_modules/lodash/_createPartial.js
ela-4.1.4 node_modules/lodash/_createPartial.js
ela-4.1.3 node_modules/lodash/_createPartial.js
optimacms-0.4.3 spec/dummy/node_modules/lodash/_createPartial.js
optimacms-0.4.2 spec/dummy/node_modules/lodash/_createPartial.js
locomotivecms-4.0.0.alpha1 app/javascript/node_modules/lodash/_createPartial.js
lux_assets-0.2.11 ./node_modules/lodash/_createPartial.js
lux_assets-0.2.9 ./node_modules/lodash/_createPartial.js
lux_assets-0.2.4 ./node_modules/lodash/_createPartial.js
lux_assets-0.2.2 ./node_modules/lodash/_createPartial.js
lux_assets-0.2.1 ./node_modules/lodash/_createPartial.js
ela-4.1.2 node_modules/lodash/_createPartial.js
sumomo-0.8.4 data/sumomo/api_modules/node_modules/lodash/_createPartial.js
ela-4.1.1 node_modules/lodash/_createPartial.js
ela-4.1.0 node_modules/lodash/_createPartial.js