So, the differences between those approaches are:
- Object, that can't be instantiated vs function (also object) with an explicit check so it can't be instantiated.
- Explicit "window.<...>" export vs declaration outside of anonymous function.
Regarding the first point, i'm indifferent, as both essentially do the same thing and your approach is a bit more to write.
You export approach has a pro in case of a module/namespace/class used across multiple scripts. While i would do this:
var IAVRA = IAVRA || {};(function() { // ...})();you can do this:
Code:
(function() { window.IAVRA || (window.IAVRA = {}); //...})();
which has the added benefit of skipping the "IAVRA = IAVRA" in case the object already exists. I actually wanted to do it this way, already, but haven't thought about using the window object itself./edit: Obviously, "= {}" can also be replaced with a function expression.