While the end result seems identical, how did he get there and what did he do in another.
The first version performs an anonymous function with this in the context of the window object. The second version performs an anonymous function, but this is in the context of a new empty object.
In the end, they both return another object (your Singleton). This is just a small difference in the context of execution.
To check this out, but alert(this); before declaring a privateVar variable.
@Tom Squires: This is not necessarily true and it is bad practice not to declare variables. A script with the "use strict"; directive "use strict"; makes the JS engine complain (assuming the engine supports "use strict" ;
Dino gambone
source share