Isolate this referance in javascript -
i trying work out style of javascript modular coding.
currently have "mount variable" declared in global.js linked pages in web application. contains global site stuff, javascript language switching:
var app = window.app || {}; app.lang = (function ($) { "use strict"; var init = function () { ... }; }; return { init: init }; })($); app.globallogic = (function ($) { "use strict"; var ready = $(function () { app.lang.init(); }); }($));
as can see, using executed functions initialize logic loaded code in file.
now trying write isolated javascript file can have similar variable names other files loaded on same page. here example:
app.galleriesadminlogic = (function ($) { "use strict"; var mountdivid = "#galleries-management-view"; ... var constructorfunction = function () { var initialdataobject = $.parsejson($(mountdivid + " #initial-galleries-list").val()); ... }($));
notice variable mountdivid
. if there similar js file loaded @ same time, contain definition variable named mountdivid
, create resolution conflict? correct pattern address same name variables local function?
variables declared inside functions local function. not visible other functions, , "hide" variables same name declared outside function.
Comments
Post a Comment