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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:02:50+00:00 2026-05-27T17:02:50+00:00

Edit: this question was asked due to my misunderstanding. Proceed with caution, as reading

  • 0

Edit: this question was asked due to my misunderstanding. Proceed with caution, as reading it might waste your time.

I thought call and apply would execute a function given a set of arguments, but I’m getting confusing test results. See my test code:

window.z = 0;
(function(){++(window.z)}).call(this, 1, 2, 3)

I would expect z to be 3 after execution. However, z is 1.

(function(){++(window.z)}).apply(this, [1, 2, 3])

Same here. z == 1;
I tried simply logging the input argument as well:

var x = function(y){console.log(y);}
x.call(this, 1, 2, 3);

Result? Only 1 is logged.
What am I doing wrong here?

(Tested in Chrome and Firefox with Firebug.)

  • 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-27T17:02:50+00:00Added an answer on May 27, 2026 at 5:02 pm

    Both call and apply only call the function once. The difference is how the arguments to the invocation are passed.

    With call, each parameter after the context (first parameter), is a parameter. With apply, the second parameter should be an array like object of parameters (the first parameter still provides the context).

    function foo(a, b, c) {
    
    };
    
    foo.call(this, 1, 2, 3); // a == 1, b == 2, c == 3;
    foo.apply(this, [1,2,3]); // a == 1, b == 2, c == 3;
    

    If you want to call the function multiple times, you can accomplish this by simply putting the call in a loop.

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

Sidebar

Related Questions

Edit : This question has already been asked and answered, and I apparently am
Edit: While this question has been asked and answered before ( 1 ), (
edit 2015 This question and its answers are no longer relevant. It was asked
A buddy of mine asked me to post this question: EDIT: He decided to
edit: this question was closed as a duplicate, but the identified duplicate was asked
I recently asked this question: Best choice? Edit bytecode (asm) or edit java file
Edit: This question was written in 2008, which was like 3 internet ages ago.
EDIT: This question is more about language engineering than C++ itself. I used C++
EDIT : This question duplicates How to access the current Subversion build number? (Thanks
(EDIT: This question is now outdated for my particular issue, as Google Code supports

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.