Skip to main content

bind

_.bind(func, thisArg) # Ⓢ [Ⓣ][1] Ⓝ

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.

Since​

0.1.0

Arguments​

  1. func (Function): The function to bind.
  2. thisArg (*): The this binding of func.

Returns​

(Function): Returns the new bound function.

Example​

function greet(punctuation) {
return this.user + punctuation;
}

var object = { user: "fred" };

var bound = _.bind(greet, object);
bound("!");
// => 'fred!'