I am attempting to reimplement apply for practice. I figured out a naive solution to execute a function in the context of an object by temporarily decorating that function on the object and then deleting it after. But I can't figure out how to pass the fn comma separated arguments when I invoke it because they are in array form.
How can I transform an array into a comma separated variables WITHOUT apply, call, or bind?
function apply(fn, context, args) {
context.fn = fn;
var result = context.fn();
delete context.fn;
return result;
}
function add(a,b) {
return a + b + this.num;
}
console.log(apply(add, {num: 10}, [3, 4])); //17
EDIT:
I do NOT want my values split into a string. I want my values split into comma separated form. This is essentially what apply does under the hood when you pass it an array.