Learning how to write JS Fn that accepts an unknown number of arguments.
function foo(a,b,c,d){
//do something
//return something
}
var bar = function () {
var arg = Array.from(arguments);
var lastIndx = arg.length;
var parArray = arg.slice(1,lastIndx);
var argMnts = arguments[0];
return arguments[0].apply(this, parArray);
};
calling bar thus works:
bar(foo,1,4,3,7);
calling it like so:
var tester = bar(foo,1,4,3,7);
tester();
results in: tester is not a function
From my research I suspected it might have to do with the scope of "this" or arguments so I assigned their values to variables, subbed the vars, and the result was the same.
Some insight would be immensely appreciated.