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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:40:15+00:00 2026-06-10T07:40:15+00:00

I am calling a method using apply and I do not know how many

  • 0

I am calling a method using apply and I do not know how many arguments I will be passing:

At the moment my code looks like this:

selectFolder: function(e){
  e.preventDefault();

  this.addSelectedClass.apply(this, Array.prototype.slice.call(arguments));
},

The only reason I am using Array.prototype.slice is because it is in most examples.

Why would I not just pass arguments like this:

 this.addSelectedClass.apply(this, 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-06-10T07:40:16+00:00Added an answer on June 10, 2026 at 7:40 am

    arguments with apply() are fine

    When calling apply on a function it’s ok to just use original arguments. SO in your example you can easily replace the line with this one:

    this.addSelectedClass.apply(this, arguments);
    

    arguments with call() are not fine

    But if you’d be calling call then you should convert arguments to an actual array (which is done by a slice() call) if you’d want to pass your function an array of arbitrary objects/values. That’s why call() is usually used when you know exactly the number of arguments you’d want to pass and pass them individually.

    arguments are not an actual array object. They seem to be (have length property for instance), but they’re not.

    Arguments on Mozilla Deveveloper Network

    A bit of explanation to make it completely clear

    Documentation related to apply() and call() looks like this:

    func.apply(thisArg[, argsArray]);
    func.call(thisArg[, arg1[, arg2[, ...]]]);
    

    We may execute the same function using any of these.

    1. When using apply() we can pass all arguments at once. slice() is usually used to omit a particular argument from the call or to convert arguments to actual array.

    2. When using call() we pass individual arguments and as many as we need to. If we’d provide arguments converted to an array, our called function would get one parameter of type array with all arguments supplied in that particular array.

    I hope this clears thing up even more.

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

Sidebar

Related Questions

Is there a way of calling a method/lines of code multiple times not using
I know this question looks like a dupe: I checked and it's not In
I expect this code (calling a method of an anonymous class after using a
I'm currently using this method in calling batch files in vb.net: Private Sub Button3_Click(ByVal
Sometimes I see people using this to call function within a widget this.myFunction.apply(this, arguments);
I have a plugin for uploading files using jquery uploadify. After calling a method
When using calling the SqlCommand.ExecuteReader() method, ReSharper tells me I have a possible NullReference
Calling the ajax called URL works well without ajax eg. http://localhost/ci/controller/method/param_value . But using
I have this code in my drawRect method float aValue = .0167f; float fValue
I am calling my controller method using .ajax. my controller method call web service

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.