主题
wrap
js
_.wrap(value, [wrapper=identity])
创建一个函数,将 value
提供给 wrapper
作为其第一个参数。将向函数提供任何其他参数附加到提供给 wrapper
的参数中。使用创建函数的 this
绑定调用封装器。
¥Creates a function that provides value
to wrapper
as its first argument. Any additional arguments provided to the function are appended to those provided to the wrapper
. The wrapper is invoked with the this
binding of the created function.
新增于
¥Since
0.1.0
参数
¥Arguments
value
(*):要封装的值。¥
value
()*: The value to wrap.[wrapper=identity]
(函数):封装函数。¥
[wrapper=identity]
(Function): The wrapper function.
返回
¥Returns
(函数):返回新函数。
¥(Function): Returns the new function.
示例
¥Example
js
var p = _.wrap(_.escape, function(func, text) {
return '<p>' + func(text) + '</p>';
});
p('fred, barney, & pebbles');
// => '<p>fred, barney, & pebbles</p>'