Version 1
[yaffs-website] / node_modules / uncss / node_modules / lodash / partial.js
1 var createWrapper = require('./internal/createWrapper'),
2     replaceHolders = require('./internal/replaceHolders'),
3     rest = require('./rest');
4
5 /** Used to compose bitmasks for wrapper metadata. */
6 var PARTIAL_FLAG = 32;
7
8 /**
9  * Creates a function that invokes `func` with `partial` arguments prepended
10  * to those provided to the new function. This method is like `_.bind` except
11  * it does **not** alter the `this` binding.
12  *
13  * The `_.partial.placeholder` value, which defaults to `_` in monolithic
14  * builds, may be used as a placeholder for partially applied arguments.
15  *
16  * **Note:** This method doesn't set the "length" property of partially
17  * applied functions.
18  *
19  * @static
20  * @memberOf _
21  * @category Function
22  * @param {Function} func The function to partially apply arguments to.
23  * @param {...*} [partials] The arguments to be partially applied.
24  * @returns {Function} Returns the new partially applied function.
25  * @example
26  *
27  * var greet = function(greeting, name) {
28  *   return greeting + ' ' + name;
29  * };
30  *
31  * var sayHelloTo = _.partial(greet, 'hello');
32  * sayHelloTo('fred');
33  * // => 'hello fred'
34  *
35  * // using placeholders
36  * var greetFred = _.partial(greet, _, 'fred');
37  * greetFred('hi');
38  * // => 'hi fred'
39  */
40 var partial = rest(function(func, partials) {
41   var holders = replaceHolders(partials, partial.placeholder);
42   return createWrapper(func, PARTIAL_FLAG, undefined, partials, holders);
43 });
44
45 module.exports = partial;