Questions tagged [module-pattern]

Popular JavaScript pattern, var Module = (function() { ... })();

Module pattern helps to avoid namespace conflicts, and thus is widely use by various third-party scripts, like libraries or banners.

Major drawbacks of using it are: much more difficult debugging and low IDE support.

var Module = (function ( ) {
      ...

})();

Original presentation at YUI blog. More detailed explanation by Ben Cherry.

Critique: by Jonathan Snook and Ed Spencer

234 questions
0
votes
1 answer

JavaScript - extract out function while keeping it private

Currently I have this structure: (function(myScope) { myScope.public = function() {alert("I'm public!")}; myScope.privileged = function() {alert("I can call private!"); private();}; var private = function() {alert("I'm…
Boyang
  • 2,520
  • 5
  • 31
  • 49
0
votes
1 answer

Module pattern: setting module-wide arrays

Despite having read all the usual tutorials on the Javascript module pattern, there's still something about scoping which I clearly don't understand. pushing to a module-wide list does what I'd expect it to do. Setting a module-wide list with =…
LondonRob
  • 73,083
  • 37
  • 144
  • 201
0
votes
1 answer

Pass object from anonymous function inside DOM ready function

Q1: How can I load the myApp object from inside the anonymous function into the DOM ready function. I know one way to pass the object is using the window.myApp = myApp; inside the anonymous function but this exposes the myApp Object as a global…
Vish
  • 383
  • 2
  • 8
  • 25
0
votes
0 answers

Load submodules from different files - javascript module pattern

I am trying to create javascript extendable library with submodules in different files. I am using Module Pattern based on Ben Cherry article module.js var SERVICES = (function (service) { var service = {}, privateVariable = 1; function…
dzeno
  • 510
  • 1
  • 5
  • 16
0
votes
1 answer

JavaScript augmented module pattern var name repeat

Can we reuse var name without overwriting its details in JavaScript.Taking below example of augmented module pattern