react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / js-yaml / node_modules / argparse / node_modules / lodash / function / bind.js
80742 viewsvar createWrapper = require('../internal/createWrapper'),1replaceHolders = require('../internal/replaceHolders'),2restParam = require('./restParam');34/** Used to compose bitmasks for wrapper metadata. */5var BIND_FLAG = 1,6PARTIAL_FLAG = 32;78/**9* Creates a function that invokes `func` with the `this` binding of `thisArg`10* and prepends any additional `_.bind` arguments to those provided to the11* bound function.12*13* The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,14* may be used as a placeholder for partially applied arguments.15*16* **Note:** Unlike native `Function#bind` this method does not set the "length"17* property of bound functions.18*19* @static20* @memberOf _21* @category Function22* @param {Function} func The function to bind.23* @param {*} thisArg The `this` binding of `func`.24* @param {...*} [partials] The arguments to be partially applied.25* @returns {Function} Returns the new bound function.26* @example27*28* var greet = function(greeting, punctuation) {29* return greeting + ' ' + this.user + punctuation;30* };31*32* var object = { 'user': 'fred' };33*34* var bound = _.bind(greet, object, 'hi');35* bound('!');36* // => 'hi fred!'37*38* // using placeholders39* var bound = _.bind(greet, object, _, '!');40* bound('hi');41* // => 'hi fred!'42*/43var bind = restParam(function(func, thisArg, partials) {44var bitmask = BIND_FLAG;45if (partials.length) {46var holders = replaceHolders(partials, bind.placeholder);47bitmask |= PARTIAL_FLAG;48}49return createWrapper(func, bitmask, thisArg, partials, holders);50});5152// Assign default placeholders.53bind.placeholder = {};5455module.exports = bind;565758