undefined
undefined

Reputation: 6453

Unnamed passed arguments not included in the 'arguments' object

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?

Upvotes: 0

Views: 71

Answers (1)

undefined
undefined

Reputation: 6453

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 arguments in the console, but in all the tests I was creating, I was doing console.log(arguments) or something similar.

If I do not reference arguments within 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.

Upvotes: 4

Related Questions