In the following example: http://jsfiddle.net/maniator/ScTAW/4/
I have this js:
var storage = (function () {
var store = [];
All arguments to console.log
will first be iterated and evaluated in order to assemble the output. As it is iterating the arguments you've passed, changes are made to objects and functions are called. After the logger has iterated the arguments, it outputs the data.
Because objects are byRef, your "second argument" changes to the storage.store
object are reflected in the console output. Because the arguments are iterated, the function call in your last argument is called before the output is assembled, so you see the output from your function call before you see the output of the first console.log
call.
It is worth noting, then, that the output of console.log
is not going to show you objects as they exist at the time of the call to console.log
. What you actually get, in the case of objects, is a reference handle to the object. Thus, any changes to the object made after the handle has been added to console.log
's output will still be reflected in the object itself. Since the handle only points to the object itself, you are not getting output showing the state of the object as it was when you called the function, but rather a live link to the object as it is now.