/*
* Example function for operating with dynamic arguments
*/
function something(){
for(var i in arguments){
arguments[i] = arguments[i] + Math.random() * 25;
}
return arguments;
}
There are no errors, have not noticed performance drops, and, the values are changed.
So, is it safe to do such operations on dynamic arguments?
I would never return it since it’s not a real array (see http://javascriptweblog.wordpress.com/2011/01/18/javascripts-arguments-object-and-beyond/ for some information about special behaviour of that object) – so depending on what the calling code does with it, it would fail.
However, you can easily turn it into an array:
I would not modify the original object since changes also change the corresponding named arguments in case your function accepts any.