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
-1
votes
1 answer

JS: what's the difference between function vs method on function expressions?

Lately I've been learning JS module pattern and I've seen at least 3-4 ways to create function expressions with public and private properties. My problem is I don't understand what's the best difference between them and what's the best approach /…
sandrina-p
  • 3,794
  • 8
  • 32
  • 60
-1
votes
1 answer

Module pattern instantiated in a window property

I need to code a module pattern instantiated in a window property. What would be the best way of doing that? var widget = (function(){ }());
Abel Abad
  • 147
  • 1
  • 2
  • 13
-1
votes
1 answer

Which design pattern to follow in creation of objects with Javascript?

Module Pattern (or) Prototype Pattern Use Case : I have to create multiple objects, but the base class is not get any derived class, I can use module pattern with common global functions instead with prototype. for Example: code 1: (module…
-1
votes
2 answers

How to use JQuery-Object in Module Pattern

I am using JQuery in a Module Pattern. I have a question about using JQuery Objects. See the following example: var myFeature = { 'config' : { 'container' : $('#myFeature'), 'init' : function(config) { …
-1
votes
1 answer

How do you implement lazy loading for a jQuery selector inside a JavaScript module?

I have written the following block of code and it works in my scenario but I know it is dirty: var navbarModule = (function($) { var self = {}; var $login; self.hideLogin = function() { $login.hide(); }; self.showLogin…
David Peden
  • 17,596
  • 6
  • 52
  • 72
-1
votes
1 answer

Check the existence of variable in the global namespace without alternate name

As a newbie in Design Patterns in Javascript, I came across the Module Pattern but I don't get something with namespace. In the namespacing part of Addy Osmani's online book about JS Design Patterns, Addy explains those 5 ways of checking for…
Iam Zesh
  • 1,797
  • 2
  • 20
  • 42
-1
votes
1 answer

MVVM UI Integration Mental Block

ive been "trying" to create a good solid framework to build an enterprise app in the html space (converting a silverlight app). I love the thought of the MVVM pattern and that makes me feel a little more at home in the javascript world. My mental…
Matt
  • 3,305
  • 11
  • 54
  • 98
-3
votes
0 answers

Problems to implement the logic that decides who is the winner on a tic tac toe game

I'm trying to implement a code that decides who is the winner but I can't figure out how to do that. I was try using conditionals and forEach to solve the problem, but seeing tutorials on internet about how to code this game, I think that my code…
-4
votes
1 answer

Javascript Module Pattern, get modified private variable as public

Can you tell me how to get modified private variable as public? let Module = (function(){ let privateObject = {}; function init(){ privateObject = {test:true} } return { init, privateObject …
Tom
  • 151
  • 6
1 2 3
15
16