Call function with an array of arguments #1006

bilus opened this Issue Mar 7, 2013 · 3 comments


None yet
3 participants

bilus commented Mar 7, 2013


I wanted to call in before branching and creating a pull request.

I created a simple helper, a close cousin of 'partial', to partially apply a function, taking an array of arguments. Seems a lot of folks find it tricky.

  splat: function(f, args) {
    return _.reduce(, function(memo, a) {
      return _.partial(memo, a);
    }, f);


function sum(x, y) {
  return x + y;

var f = _.splat(sum, [4, 5]);

(The name is based on 'splat' operator in Ruby.)

Should I add tests and create a pull request or would you rather pass?

Thank you for this wonderful library.

Take care,


michaelficarra commented Mar 7, 2013

This is just a Function.prototype.apply wrapper, right? -1

bilus commented Mar 8, 2013

I think you may be (at least partially) right but how about using apply without a context (this)?

I must be missing something so if it turns out there's a built-in method for this, I'll be happy to get rid of some extra fat from my project's code. :)

bilus closed this Mar 8, 2013

bilus reopened this Mar 8, 2013


jashkenas commented May 26, 2013

Just pass null for the context if you don't care what it is.

jashkenas closed this May 26, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment