SIGN IN SIGN UP

A modern JavaScript utility library delivering modularity, performance, & extras.

0 0 33 JavaScript
2016-10-30 20:06:57 -07:00
define(['./_castFunction', './partial'], function(castFunction, partial) {
2015-01-08 00:37:01 -08:00
/**
2016-07-24 09:52:04 -07:00
* 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.
2015-01-08 00:37:01 -08:00
*
* @static
* @memberOf _
2016-03-26 00:00:01 -07:00
* @since 0.1.0
2015-01-08 00:37:01 -08:00
* @category Function
* @param {*} value The value to wrap.
2016-02-15 20:20:54 -08:00
* @param {Function} [wrapper=identity] The wrapper function.
2015-01-08 00:37:01 -08:00
* @returns {Function} Returns the new function.
* @example
*
* var p = _.wrap(_.escape, function(func, text) {
* return '<p>' + func(text) + '</p>';
* });
*
* p('fred, barney, & pebbles');
* // => '<p>fred, barney, &amp; pebbles</p>'
*/
function wrap(value, wrapper) {
2016-10-30 20:06:57 -07:00
return partial(castFunction(wrapper), value);
2015-01-08 00:37:01 -08:00
}
return wrap;
});