It has been widely used nowadays to wrap JavaScript libraries, as seen
in JQuery.
(function() {
var global = this;
// ...
})();
The advantage, as I learned, is the isolation from other global
variables. But how? What other advantages does this wrapper have. For
example, I have my library as:
var myLib = {
go : function(){
alert('Hah')
},
arr : new Array()
}
How would I write myLib in (function(){})( ) format? Do I need to? What
are the advantages?
Please clear for me if you can.
Thanks
in JQuery.
(function() {
var global = this;
// ...
})();
The advantage, as I learned, is the isolation from other global
variables. But how? What other advantages does this wrapper have. For
example, I have my library as:
var myLib = {
go : function(){
alert('Hah')
},
arr : new Array()
}
How would I write myLib in (function(){})( ) format? Do I need to? What
are the advantages?
Please clear for me if you can.
Thanks
Comment