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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:25:09+00:00 2026-05-23T08:25:09+00:00

Is this legal? And does it work in all browsers? function func1(a, b, c)

  • 0

Is this legal? And does it work in all browsers?

function func1(a, b, c) {
  //b == 2 here
  change_em(arguments);
  //b should equal 3 here
}

function change_em(args) {
  args[0] = 6;
  args[1]++;
  args[2] = [];
}

func1('foo', 2);

If you are wondering, I need to adjust the arguments in a function. A macro would be perfect, except javascript doesn’t have one. Doing it properly, i.e. passing the variables to a function, then returning them in an object, and then extracting them in the caller would be almost as much code as just copy/pasting the adjuster function.

  • 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-23T08:25:09+00:00Added an answer on May 23, 2026 at 8:25 am

    It is valid under EcmaScript 3 and EcmaScript 5 non-strict, but it is not valid under EcmaScript 5 strict mode. It works in all modern browsers and most old ones. It should not work in strict mode such as when run in Firefox 5 with a "use strict" directive.

    From the EcmaScript 5 spec section 10.6.11.c.ii

    10.6 Arguments Object

    …

    If strict is false and name is not an element of mappedNames, then

    1. Add name as an element of the list mappedNames.

    2. Let g be the result of calling the MakeArgGetter abstract operation with arguments
      name and env.

    3. Let p be the result of calling the MakeArgSetter abstract operation with arguments
      name and env.

    4. Call the [[DefineOwnProperty]] internal method of map passing ToString(indx), the
      Property Descriptor {[[Set]]: p, [[Get]]: g, [[Configurable]]: true}, and false as
      arguments.

    Basically, the arguments object gets a setter for each index so that assigning to arguments[i] changes the value of the named parameter at position i. There is language in the spec which makes it work vice-versa.

    This should work in non-strict mode in any interpreter

    (function (x) {
      alert("x=" + x + ", arguments[0]=" + arguments[0]);  // Both should be 0
      arguments[0] = 1;
      alert("x=" + x + ", arguments[0]=" + arguments[0]);  // both should be 1
      x = 2;
      alert("x=" + x + ", arguments[0]=" + arguments[0]);  // both should be 2
     })(0);
    

    But if you run the above on Firefox 5 with a use strict directive you get different behavior:

    (function (x) {
      "use strict";
    
      alert("x=" + x + ", arguments[0]=" + arguments[0]);  // Both should be 0
      arguments[0] = 1;
      alert("x=" + x + ", arguments[0]=" + arguments[0]);  // x=0, arguments[0]=1
      x = 2;
      alert("x=" + x + ", arguments[0]=" + arguments[0]);  // x=2, arguments[0]=1 
     })(0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anybody please spot my error, this should be a legal query in SQL
byte b=12; b >>= 2; // Why is this legal? why does it automatically
Is this legal? Does it contain a hidden bug or flaw? Visual studio does
Is this legal and/or good practice? #define SOFTWARE_VERSION_NUMBER 7.0v1.1 Want struct to always contain
This isn't legal: public class MyBaseClass { public MyBaseClass() {} public MyBaseClass(object arg) {}
You may argue that this question has a legal flavor to it, and that
int main() { int *d=0; printf(%d\n,*d); return 0; } this works fine. >cc legal.c
Is this valid/portable/legal code: class Vector3 { public: float& operator [] ( const size_t
Does this code solve the double checked locking issue in Java? public class DBAccessService()
I want to develop a C++ application that will work on ALL operating systems.

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.