_.bind

_.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

  1. func (Function): The function to bind.
  2. thisArg (*): The this binding of func.
  3. [partials] (...*): The arguments to be partially applied.

Returns

(Function): Returns the new bound function.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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!'
doc_Lodash
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.