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 893651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:15:21+00:00 2026-05-15T14:15:21+00:00

I think I need something like ruby’s splat * here. function foo() { var

  • 0

I think I need something like ruby’s splat * here.

function foo() {
  var result = '';
  for (var i = 0; i < arguments.length; i++) {
    result += arguments[i];
  }
  return result;
}

function bar() {
  return foo(arguments) // this line doesn't work as I expect
}

bar(1, 2, 3);

I want this to return "123", but instead I get "[object Arguments]". Which makes sense, I suppose. It’s passing the object that represents the arguments, but not the arguments individually.

So how do I simply forward any number of arguments to another function that takes any number of arguments?

  • 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-15T14:15:22+00:00Added an answer on May 15, 2026 at 2:15 pm

    UPDATE: Since ES6, you can use the spread syntax to call a function, applying the elements of an iterable object as argument values of the function call:

    function bar() {
      return foo(...arguments);
    }
    

    Note that you can also receive a variable number of arguments as a real array, instead of using the arguments object.

    For example:

    function sum(...args) { //  args is an array
      return args.reduce((total, num) => total + num)
    }
    
    function bar(...args) {
      return sum(...args) // this just forwards the call spreading the argument values
    }
    
    console.log(bar(1, 2, 3)); // 6

    In the days of ES3/ES5, to correctly pass the arguments to another function, you needed to use apply:

    function bar() {
      return foo.apply(null, arguments);
    }
    

    The apply method takes two parameters, the first is the thisObj, the value of it will be used as the this value inside the invoked function, if you use null or undefined, the this value inside the function will refer to the global object, in non-strict mode, otherwise is undefined.

    The second argument that apply expects is an array-like object that contains the argument values to be applied to the function.

    Check the above example here.

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

Sidebar

Related Questions

I think I might need to do something like the following pseudo-code in my
I think I need something akin to a rails eager loaded query with a
I think I need a reverse version of strtok, like: char* p = rstrtok(str,
After looking at several questions/answers here, I'm not seeing what I think I need.
I need to create something like this: paxReference => [{ ptc => ADT, traveller
i have 3 models like : location, user, discovered_location(location_id,user_id) I think i need an
I need something like a session-id. I will need to track a couple of
I need to add full web search to my site. I need something like
I think I need a way to perform a pivot or crosstab using C#
I don't think I need to post my code (there's lots of it) but

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.