2016-04-20 00:43:12 +02:00
|
|
|
// @allowJs: true
|
|
|
|
// @out: apply.js
|
|
|
|
// @module: amd
|
|
|
|
|
|
|
|
// @filename: _apply.js
|
|
|
|
/**
|
|
|
|
* A faster alternative to `Function#apply`, this function invokes `func`
|
|
|
|
* with the `this` binding of `thisArg` and the arguments of `args`.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Function} func The function to invoke.
|
|
|
|
* @param {*} thisArg The `this` binding of `func`.
|
|
|
|
* @param {...*} args The arguments to invoke `func` with.
|
|
|
|
* @returns {*} Returns the result of `func`.
|
|
|
|
*/
|
2017-11-15 22:04:08 +01:00
|
|
|
function apply(func, thisArg, ...args) {
|
2016-04-20 00:43:12 +02:00
|
|
|
var length = args.length;
|
|
|
|
switch (length) {
|
|
|
|
case 0: return func.call(thisArg);
|
|
|
|
case 1: return func.call(thisArg, args[0]);
|
|
|
|
case 2: return func.call(thisArg, args[0], args[1]);
|
|
|
|
case 3: return func.call(thisArg, args[0], args[1], args[2]);
|
|
|
|
}
|
|
|
|
return func.apply(thisArg, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default apply;
|