With this code:
function printStuff(thing1, thing2) {
console.log(thing1);
console.log(thing2);
};
function callWith(func, args) {
return function () {
func.apply(this, args);
};
}
function callWith2() {
theFunc = arguments[0];
theArgs = arguments.slice(1);
return function() {
theFunc.apply(this, theArgs);
};
};
x = callWith(printStuff, ["apples", "cheese"]);
x();
y = callWith2(printStuff, "apples", "cheese");
y();
...why is it that using callWith works but using callWith2 throws an error?
Is there any way to achieve this functionality (namely, a function which takes a function as its first argument and an arbitrary number of other arguments(NOT as a list), and feeds those arguments into the function argument to create an anonymous function it returns)?