In a jQuery web application, I have various scripts where several files can be included, and I use only one of them at a time (I know that not including all of them would be better, but I'm just responsible for JS, not my decision). So I wrap each file in an init Module () function that logs various events and does some initialization, etc.
Now I'm curious if there are differences between the two ways of defining functions that do not clutter the global namespace:
function initStuff(someArg) { var someVar = 123; var anotherVar = 456; var somePrivateFunc = function() { } var anotherPrivateFunc = function() { } }
and
function initStuff(someArg) { var someVar = 123; var anotherVar = 456; function somePrivateFunc() { } function anotherPrivateFunc() { } }
javascript scope
Thiefmaster
source share