1 var createWrapper = require('./_createWrapper'),
2 replaceHolders = require('./_replaceHolders'),
3 rest = require('./rest');
5 /** Used to compose bitmasks for wrapper metadata. */
10 * Creates a function that invokes `func` with the `this` binding of `thisArg`
11 * and prepends any additional `_.bind` arguments to those provided to the
14 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
15 * may be used as a placeholder for partially applied arguments.
17 * **Note:** Unlike native `Function#bind` this method doesn't set the "length"
18 * property of bound functions.
23 * @param {Function} func The function to bind.
24 * @param {*} thisArg The `this` binding of `func`.
25 * @param {...*} [partials] The arguments to be partially applied.
26 * @returns {Function} Returns the new bound function.
29 * var greet = function(greeting, punctuation) {
30 * return greeting + ' ' + this.user + punctuation;
33 * var object = { 'user': 'fred' };
35 * var bound = _.bind(greet, object, 'hi');
39 * // Bound with placeholders.
40 * var bound = _.bind(greet, object, _, '!');
44 var bind = rest(function(func, thisArg, partials) {
45 var bitmask = BIND_FLAG;
46 if (partials.length) {
47 var placeholder = bind.placeholder,
48 holders = replaceHolders(partials, placeholder);
50 bitmask |= PARTIAL_FLAG;
52 return createWrapper(func, bitmask, thisArg, partials, holders);
55 // Assign default placeholders.
56 bind.placeholder = {};
58 module.exports = bind;