Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6470461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:06:51+00:00 2026-05-25T06:06:51+00:00

How do I apply the same arguments to an array of functions? Works: async.parallel([func(arg,

  • 0

How do I apply the same arguments to an array of functions?

Works:

async.parallel([func(arg, arg2), func2(arg, arg2)],
function() {
  next();
});

The array has indeterminate / various functions functions inside though, so I’m not sure which functions I should be sending to the parallel method.

In various files I’m building the functions array:

funcArray.push(func2)

As a result I have an array like this:

[func, func2]

I would like to just do:

async.parallel(funcArray,
function() {
  next();
});

and have all the same arguments be applied to all the functions. How can I do this? Thanks.

Ended up writing my own:

  _.each(obj, function (func) {
    func(req, res, function () {
      i++
      if (i == objSize) {
        next()
      }
    })
  })      
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:06:52+00:00Added an answer on May 25, 2026 at 6:06 am

    Untested, but this ought to work:

    var args      = [ arg, arg2 ]
      , funcCalls = []
    ;
    
    for(var i = 0; i < funcArray.length; i++) {
      funcCalls.push(function() {
        funcArray[i].apply(this, args); }
      );
    }
    
    async.parallel(funcCalls, next);
    

    Or, if you already know how many arguments you’ll have, you don’t need to use apply in the middle section:

    for(var i = 0; i < funcArray.length; i++) {
      funcCalls.push(function() {
        funcArray[i](arg, arg2); }
      );
    }
    

    And finally you could really tighten it up with a map function as provided by e.g. Underscore.js:

    async.parallel(_.map(funcArray,
      function(func) { return function() { func(arg, arg2); } }
    ), next);
    

    …but then the next guy who comes across your code might kill you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Specman has the apply() method to perform the same action on all elements of
I wanted to invoke a function using the javascript apply() method. This works fine
If I have a function as such: function doStuff(arg) { arguments[0] = 4 +
Example: I have two shared objects (same should apply to .dlls). The first shared
Do the same best practis rules regarding subscribing/unsubscribing to events apply in asp.net? I
How does the Same Origin Policy apply to the following two domains? http://server1.MyDomain.com http://server2.MyDomain.com
It's about PHP but I've no doubt many of the same comments will apply
Why do browsers apply the same origin policy to XMLHttpRequest? It's really inconvenient for
I have to apply the same data trigger on multiple items. Data trigger is
Possible Duplicate: How can I pre-set arguments in JavaScript function call? (Partial Function Application)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.