00001 var apply = require('./_apply'),
00002 arrayPush = require('./_arrayPush'),
00003 baseRest = require('./_baseRest'),
00004 castSlice = require('./_castSlice'),
00005 toInteger = require('./toInteger');
00006
00008 var FUNC_ERROR_TEXT = 'Expected a function';
00009
00010
00011 var nativeMax = Math.max;
00012
00047 function spread(func, start) {
00048 if (typeof func != 'function') {
00049 throw new TypeError(FUNC_ERROR_TEXT);
00050 }
00051 start = start == null ? 0 : nativeMax(toInteger(start), 0);
00052 return baseRest(function(args) {
00053 var array = args[start],
00054 otherArgs = castSlice(args, 0, start);
00055
00056 if (array) {
00057 arrayPush(otherArgs, array);
00058 }
00059 return apply(func, this, otherArgs);
00060 });
00061 }
00062
00063 module.exports = spread;