Suppose I have core.js
var ajax = function(){};
var something = function(){super};
var globalconstant = 5;
var someutilitymodule = {
onekey: something;
twokey: something;
}
If I include this in my file as <script src="core.js">
1) I pollute the global namespace
2) Might [replace/get replaced by] another variable .
However won't making it an Object solve the problem ? I.e I make core.js like this
core =
{
ajax : function(){},
something : function(){super},
globalconstant : 5,
someutilitymodule = {
onekey: something;
twokey: something;
}
}
What is the fundamental problem in this approach ? Is it because that you can't access other items until the full Object is created ? Like for example core = {a:"Foo" , b:a}
won't work ?
However I could solve it by
core = {};
core.a="Foo";
core.b=core.a;
Why do we have to get into IIFE(Immediately Invoked Function Expression) if we are not really interested in closures ? For "module namespace" in Javascript that doesn't mind having everything public in a different namespace , won't this approach work and create Module effect in Javascript ?
Are there any pointers to read more on this ? I know its a bit vague but I am new to this concepts like IIFE requirejs etc . So trying to understand from a newbie perspective .