Sha256: c0a9d31fa28c7b583a52e4d6d77cd012cbc400cf811b156fbae8b390efc5532b

Contents?: true

Size: 1.65 KB

Versions: 270

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

270 entries across 269 versions & 28 rubygems

Version Path
disco_app-0.18.2 test/dummy/node_modules/lodash/bind.js
sumomo-0.8.15 data/sumomo/api_modules/node_modules/lodash/bind.js
trusty-cms-5.0.7 node_modules/lodash/bind.js
appmap-0.72.2 ./node_modules/lodash/bind.js
trusty-cms-5.0.6 node_modules/lodash/bind.js
appmap-0.72.1 ./node_modules/lodash/bind.js
appmap-0.72.0 ./node_modules/lodash/bind.js
trusty-cms-5.0.5 node_modules/lodash/bind.js
trusty-cms-5.0.4 node_modules/lodash/bind.js
appmap-0.71.0 ./node_modules/lodash/bind.js
disco_app-0.16.1 test/dummy/node_modules/lodash/bind.js
appmap-0.70.2 ./node_modules/lodash/bind.js
sumomo-0.8.14 data/sumomo/api_modules/node_modules/lodash/bind.js
appmap-0.70.1 ./node_modules/lodash/bind.js
appmap-0.70.0 ./node_modules/lodash/bind.js
appmap-0.69.0 ./node_modules/lodash/bind.js
sumomo-0.8.13 data/sumomo/api_modules/node_modules/lodash/bind.js
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