Sha256: c0a9d31fa28c7b583a52e4d6d77cd012cbc400cf811b156fbae8b390efc5532b

Contents?: true

Size: 1.65 KB

Versions: 273

Compression:

Stored size: 1.65 KB

Contents

var baseRest = require('./_baseRest'),
    createWrap = require('./_createWrap'),
    getHolder = require('./_getHolder'),
    replaceHolders = require('./_replaceHolders');

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

/**
 * Creates a function that invokes `func` with the `this` binding of `thisArg`
 * and `partials` prepended to the arguments it receives.
 *
 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
 * may be used as a placeholder for partially applied arguments.
 *
 * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
 * property of bound functions.
 *
 * @static
 * @memberOf _
 * @since 0.1.0
 * @category Function
 * @param {Function} func The function to bind.
 * @param {*} thisArg The `this` binding of `func`.
 * @param {...*} [partials] The arguments to be partially applied.
 * @returns {Function} Returns the new bound function.
 * @example
 *
 * function greet(greeting, punctuation) {
 *   return greeting + ' ' + this.user + punctuation;
 * }
 *
 * var object = { 'user': 'fred' };
 *
 * var bound = _.bind(greet, object, 'hi');
 * bound('!');
 * // => 'hi fred!'
 *
 * // Bound with placeholders.
 * var bound = _.bind(greet, object, _, '!');
 * bound('hi');
 * // => 'hi fred!'
 */
var bind = baseRest(function(func, thisArg, partials) {
  var bitmask = WRAP_BIND_FLAG;
  if (partials.length) {
    var holders = replaceHolders(partials, getHolder(bind));
    bitmask |= WRAP_PARTIAL_FLAG;
  }
  return createWrap(func, bitmask, thisArg, partials, holders);
});

// Assign default placeholders.
bind.placeholder = {};

module.exports = bind;

Version data entries

273 entries across 272 versions & 29 rubygems

Version Path
appmap-0.68.2 ./node_modules/lodash/bind.js
appmap-0.68.1 ./node_modules/lodash/bind.js
disco_app-0.15.2 test/dummy/node_modules/lodash/bind.js
appmap-0.68.0 ./node_modules/lodash/bind.js
appmap-0.67.1 ./node_modules/lodash/bind.js
trusty-cms-5.0.3 node_modules/lodash/bind.js
trusty-cms-5.0.2 node_modules/lodash/bind.js
appmap-0.67.0 ./node_modules/lodash/bind.js
disco_app-0.18.4 test/dummy/node_modules/lodash/bind.js
disco_app-0.18.1 test/dummy/node_modules/lodash/bind.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/lodash/bind.js
disco_app-0.14.0 test/dummy/node_modules/lodash/bind.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/lodash/bind.js
appmap-0.66.2 ./node_modules/lodash/bind.js
trusty-cms-5.0.1 node_modules/lodash/bind.js
trusty-cms-4.3.5 node_modules/lodash/bind.js
trusty-cms-5.0.0 node_modules/lodash/bind.js
appmap-0.66.1 ./node_modules/lodash/bind.js
appmap-0.66.0 ./node_modules/lodash/bind.js
appmap-0.65.1 ./node_modules/lodash/bind.js