主题
partial
js
_.partial(func, [partials])
创建一个调用 func
的函数,并在其收到的参数前面添加 partials
。此方法类似于 _.bind
,只是它不会改变 this
绑定。
¥Creates a function that invokes func
with partials
prepended to the arguments it receives. This method is like _.bind
except it does not alter the this
binding.
_.partial.placeholder
值在单片构建中默认为 _
,可用作部分应用参数的占位符。
¥The _.partial.placeholder
value, which defaults to _
in monolithic builds, may be used as a placeholder for partially applied arguments.
注意:此方法不设置部分应用函数的 "length" 属性。
¥Note: This method doesn't set the "length" property of partially applied functions.
新增于
¥Since
0.2.0
参数
¥Arguments
func
(函数):部分应用参数的函数。¥
func
(Function): The function to partially apply arguments to.[partials]
(...*):要部分应用的参数。¥
[partials]
(...)*: The arguments to be partially applied.
返回
¥Returns
(函数):返回新的部分应用函数。
¥(Function): Returns the new partially applied function.
示例
¥Example
js
function greet(greeting, name) {
return greeting + ' ' + name;
}
var sayHelloTo = _.partial(greet, 'hello');
sayHelloTo('fred');
// => 'hello fred'
// Partially applied with placeholders.
var greetFred = _.partial(greet, _, 'fred');
greetFred('hi');
// => 'hi fred'