In javascript when you define an object literal, where does that object exist? Is that in the activation object of that function? I’m asking this to know if there is any technical difference between this or any other implications:
var global;
(function(){
global={};
})();
or:
var global = {};
An object doesn’t have any scope, so it doesn’t make any difference where you create it.
However, if the object has methods, they can use local variables of the scope where they are created:
The local variable
localonly exists inside that scope, but the method in the object can use the variable as the method is created inside the scope.The same works with an object created outside the scope, as long as the method is created inside the scope;