javascript - What does ;(function(global,$,_){ }(app,jQuery,_)); mean? -


this question has answer here:

in 1 javascript file, script wrapped this, why wrap codes this? reference this? why define basepage=global.basepage?

;(function (global,$,_) {   var basepage=global.basepage = backbone.view.extend({}); }(app,jquery,_)); 

by setting var basepage, basepage become local variable in function, , don't need write global.basepage further references. organization has several benefits, , i'll try list each.

  1. any variables inside function inaccessible other parts of code. useful if declare common name var x or var element , don't want mixed others global variable.
  2. inside function, 'app' referred 'global'. setting 'global.basepage = backbone.etc...' means after function executed, app have basepage property.
  3. some javascript loader-frameworks depend on style able initialize module after of dependencies (like jquery) have loaded.