Removed modules/contrib/media module to allow update to the core media module
[yaffs-website] / node_modules / uncss / node_modules / lodash / internal / createPartialWrapper.js
1 var apply = require('./apply'),
2     createCtorWrapper = require('./createCtorWrapper');
3
4 /** Used to compose bitmasks for wrapper metadata. */
5 var BIND_FLAG = 1;
6
7 /**
8  * Creates a function that wraps `func` to invoke it with the optional `this`
9  * binding of `thisArg` and the `partials` prepended to those provided to
10  * the wrapper.
11  *
12  * @private
13  * @param {Function} func The function to wrap.
14  * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details.
15  * @param {*} thisArg The `this` binding of `func`.
16  * @param {Array} partials The arguments to prepend to those provided to the new function.
17  * @returns {Function} Returns the new wrapped function.
18  */
19 function createPartialWrapper(func, bitmask, thisArg, partials) {
20   var isBind = bitmask & BIND_FLAG,
21       Ctor = createCtorWrapper(func);
22
23   function wrapper() {
24     var argsIndex = -1,
25         argsLength = arguments.length,
26         leftIndex = -1,
27         leftLength = partials.length,
28         args = Array(leftLength + argsLength),
29         fn = (this && this !== global && this instanceof wrapper) ? Ctor : func;
30
31     while (++leftIndex < leftLength) {
32       args[leftIndex] = partials[leftIndex];
33     }
34     while (argsLength--) {
35       args[leftIndex++] = arguments[++argsIndex];
36     }
37     return apply(fn, isBind ? thisArg : this, args);
38   }
39   return wrapper;
40 }
41
42 module.exports = createPartialWrapper;