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

  • Home
  • SEARCH
  • 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 9239891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:05:43+00:00 2026-06-18T08:05:43+00:00

q.ninvoke(myNodeJsFunc).then(function(result) { console.log(arguments); }); function myNodeJsFunc(callback) { callback(null, arg1, arg2, …, argN); // first

  • 0
q.ninvoke(myNodeJsFunc).then(function(result) {
    console.log(arguments);
});

function myNodeJsFunc(callback) {
    callback(null, arg1, arg2, ..., argN); // first argument is null as no error occurred
}

If I only pass back arg1, result will be arg1. If I pass back multiple arguments, result will be an array of arguments. Is there a way to have Q call back with each of my arguments applied to the function as individual arguments, rather than being bundled into an array and passed back as a single argument? I was hoping to be able to use named arguments rather than having to sift through an array of arbitrary elements.

Effectively, I would like to be able to do this:

q.ninvoke(myNodeJsFunc).then(function(arg1, arg2, arg3) {
    // do stuff
    if(arg2) {
        // do stuff
    }
    // etc.
});
  • 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-06-18T08:05:44+00:00Added an answer on June 18, 2026 at 8:05 am

    You can, what you’re after is called spread:

    q.ninvoke(myNodeJsFunc)
      .spread(function(arg1, arg2, arg3) {
        // do stuff
        if(arg2) {
          // do stuff
        }
        // etc.
      });
    

    The reason this isn’t the default is that part of the premise behind promises is to make them as much like the synchronous counterparts as possible. That way in the future you’ll be able to do:

    spawn(function* () {
      var res = yield q.ninvoke(myNodeJsFunc);
      res[0], res[1]...
    });
    

    Which looks synchronous, except for the yield keyword which is where the magic happens.

    The spread operator is fine because in the next version of JavaScript you would be able to write:

    spawn(function* () {
      let [arg1, arg2, arg3...] = yield q.ninvoke(myNodeJsFunc);
      arg1, arg2 ...
    });
    

    which nicely parallels the synchronous codde:

    let [arg1, arg2, arg3...] = mySyncFunc();
    arg1, arg2 ...
    

    In short, when you want multiple arguments, replace then with spread.

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

Sidebar

Related Questions

We have a class example and I just don't get it. I don't quite
I'm trying to narrow down the potential causes of memory issues I'm having with
I have 2 assembly methods: DWToHex PROTO:DWORD modifies binary integer number of type DWORD

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.