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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:50:13+00:00 2026-06-01T01:50:13+00:00

I’m trying to write a function that would use its first argument, then send

  • 0

I’m trying to write a function
that would use its first argument, then send the rest (not known how many) to another one:

function consume_data() {
   args = consume_data.arguments;
   do_some(args[0]);
   consume_the_rest(args[1], args[2], args[3] ... );
}

Do I have to use strings to compose the call and eval or is there a neater way?

  • 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-01T01:50:14+00:00Added an answer on June 1, 2026 at 1:50 am

    The traditional JavaScript way… unfortunately.

    function consume_data() {
    
        do_some(arguments[0]);
    
        var args = Array.prototype.slice.call(arguments, 1);
    
        consume_the_rest.apply(this, args);
    }
    

    You should use the arguments variable that’s provided in the local variable scope. Then borrow .slice() from Array.prototype to get an Array of arguments starting with the second.

    Then use the .apply() method to pass those arguments as a collection, which will be destructured into individual arguments in the consome_the_rest method.


    Why?

    The reason you need to borrow Array.prototype.slice is that an arguments object is not really an Array, so it doesn’t have the prototyped Array methods.

    The first argument given to .apply() sets the calling context (this value) of the function you’re calling, and as I mentioned above, the args Array will be destructured into individual arguments in the execution context of the function you’re calling. This is what make it possible to pass an unknown number of arguments.


    An alternative, with caveats.

    If you don’t care about the calling context of the function, you can actually do this instead…

    function consume_data() {
    
        do_some(arguments[0]);
    
        consume_the_rest.call.apply(consume_the_rest, arguments);
    }
    

    Here the .call() method is just like .apply() except that you pass arguments individually instead of as a collection. So we’re calling .call() using .apply(), which will set the consume_the_rest as the calling context of .call(), and spread the arguments out, setting the first argument as the calling context arg of .call(), and the rest the normal arguments to be passed on.

    It will be as though you did…

    consume_the_rest.call(arguments[0], arguments[1], ...arguments[n])
    

    …so the first argument will actually be used as the calling context, and the rest will be the ones you expect.

    Again, only do this if you don’t care about the calling context of the function you’re calling.

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

Sidebar

Related Questions

I need a function that will clean a strings' special characters. I do NOT
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string

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.