I noticed while debugging some Javascript that an extra argument that I was passing was not showing up in the arguments object. The function declaration had one named argument, and was being passed two arguments, but the arguments array only contained the first argument. When trying to duplicate the problem in the Javascript console or a jsfiddle, the arguments are always passed properly. What could the problem be?
I noticed while debugging some Javascript that an extra argument that I was passing
Share
The problem, which was only happening in Chrome, appears to be a Chrome optimization. What I did not realize at first is that in the original function where I found that arguments was incomplete, I was inspecting
argumentsin the console, but in all the tests I was creating, I was doingconsole.log(arguments)or something similar.If I do not reference
argumentswithin a function, Chrome does not go to the expense of populating it. Thus, when inspecting arguments through the console, it only shows the arguments which are present as named parameters. I have created a jsfiddle to demonstrate this: http://jsfiddle.net/bgmort/2kmJs/Since I spent a couple hours searching for the answer to this, I hope that documenting what I found will save someone else a little time.