The code below works fine in FF3.X and IE7 to 9, but not in FF4.
I have this code in 2 places in my file:
var arguments = "method=getoptions";
arguments += "&dropzone=" + dictKey;
arguments += "&format=disc";
arguments += "&datasetid=" + datasetid;
arguments += "&varnumber=" + varnumber;
arguments += "&varSectionId=" + varSectionId;
arguments += "&catindex=" + catIndex;
arguments += "&defaultid=dv_cat_opts_default_body";
arguments += "&mmocid=dv_cat_opts_mmoc_body";
alert(arguments);
which produces
method=getoptions&dropzone=Row_1&format=disc&datasetid=1&varnumber=206&varSectionId=FUV&catindex=&defaultid=dv_cat_opts_default_body&mmocid=dv_cat_opts_mmoc_body
and that is correct, but the same code elsewhere in the file
var arguments = "method=getoptions";
arguments += "&dropzone=" + dictKey;
arguments += "&format=disc";
arguments += "&datasetid=" + datasetid;
arguments += "&varnumber=" + varnumber;
arguments += "&varSectionId=" + varSectionId;
arguments += "&catindex=" + catIndex;
arguments += "&defaultid=dv_cat_opts_default_body";
arguments += "&mmocid=dv_cat_opts_mmoc_body";
alert(arguments);
outputs this which ends up calling an error in my ajax:
[object Arguments]&dropzone=Row_1&format=cont&datasetid=1&varnumber=1125&varSectionId=FUV&catindex=&defaultid=dv_cont_opts_default_body&mmocid=dv_cont_opts_mmoc_body
So what’s the deal with that object Arguments?
The variable
argumentsis a special object available within functions, it contains all the arguments passed to a function.https://developer.mozilla.org/en/JavaScript/Reference/functions_and_function_scope/arguments
To put it another way, consider the variable name
argumentsto be a reserved keyword – just like you would never name a variableif, don’t use the variable nameargumentsor you will get unexpected results.Why is this thing here, you might ask – it lets you write your functions that use a varying number and order of arguments. Within your function, you’d write code to determine which arguments were passed and what they are. It takes quite a bit more code, but you can create some pretty flexible reusable code with this technique. Check out some of the internal functions for Mootools or jQuery and you’ll see that these popular frameworks make heavy use of the
argumentsobject.Consider:
Try it here: http://jsfiddle.net/zwGMJ/