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