_.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
func
(Function): The function to bind.thisArg
(*): Thethis
binding offunc
.[partials]
(…*): The arguments to be partially applied.
Returns
(Function): Returns the new bound function.
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!'
当前内容版权归 lodash.com 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 lodash.com .