When returning .bind() from a higher order function, is it possible to access the arguments collection within the bound context?
Take the following function as an example:
function reverse(fn) {
return function () {
return fn.apply(this, [].slice.call(arguments).reverse())
};
}
Ideally I'd like to remove the inner function wrapper and simply return something like:
return fn.apply.bind(fn, [].slice.call(arguments).reverse());
(Obviously arguments is scoped to the outer function and not the returned function, which is what I'm after).
Is this possible through some mechanism I'm unaware of or is the function wrapper a necessity?
return function () {...})reverse(console.log)("World", "Hello") -> "Hello" "World"