4.17.11
3.10.1
2.4.2
1.3.1
_.bind(func, thisArg, [partials])
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
argument
functhisArg[partials]type
Function
*
...*
description
The function to bind.
The `this` binding of `func`.
The arguments to be partially applied.
Returns
(array)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!'
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!'