I am trying to write a JavaScript function that will return its first argument(function) with all the rest of its arguments as preset parameters to that function.
So:
function out(a, b) { document.write(a + ' ' + b); } function setter(...) {...} setter(out, 'hello')('world'); setter(out, 'hello', 'world')();
Would output ‘hello world’ twice. for some implementation of setter
I ran into an issue with manipulating the arguments array on my first try, but it seems there would be a better way to do this.
First of all, you need a partial – there is a difference between a partial and a curry – and here is all you need, without a framework:
Now, using your example, you can do exactly what you are after:
The
partial()function could be used to implement, but is not currying. Here is a quote from a blog post on the difference: