Questions tagged [revealing-module-pattern]

The Revealing Module Pattern is an updated Module Pattern where you define all of your functions and variables in the private scope and return an anonymous object at the end of the module along with pointers to both the private variables and functions you wish to reveal as public.

179 questions
2
votes
1 answer

'Undefined' when returning object from JS module

I have defined a global variable and then set it equal to a method made available through one of my modules which renders a chart. The module should return a chart, thus assigning the variable 'alChart' a chart object. It is also worth mentioning…
Tomuke
  • 869
  • 2
  • 8
  • 26
2
votes
2 answers

Trying to understand the behavior of this function definition

I wasn't sure how to title this question, but I'm using the revealing module pattern with constructors and noticed some behavior that confused me. The actual purpose of this code is irrelevant to my question I just want to understand this behavior I…
red888
  • 27,709
  • 55
  • 204
  • 392
2
votes
2 answers

Java Script Revealing Module Pattern create multiple objects

I need suggestions about writing better code in Revealing Module Pattern way. I have followed tutorial http://weblogs.asp.net/dwahlin/archive/2011/09/05/creating-multiple-javascript-objects-when-using-the-revealing-module-pattern.aspx which help me…
Pravin W
  • 2,451
  • 1
  • 20
  • 26
2
votes
2 answers

JavaScript revealing module pattern public variable not updating

I'm using Angular service with a Revealing Module pattern. The service internally pulls string resources from a web service and makes them available via the 'Strings' public variable. I have to initialize the private 'strings' variable because it…
programmerj
  • 1,634
  • 18
  • 29
2
votes
1 answer

Why are functions assigned to variables in the module pattern?

In the Module Pattern example from Addy Osmani, a private function is assigned to a variables as shown in this example: var myNamespace = (function () { var myPrivateVar, myPrivateMethod; // A private counter variable myPrivateVar = 0; //…
Jamie Ide
  • 48,427
  • 16
  • 81
  • 117
2
votes
3 answers

Javascript Revealing Module Pattern - this and internal function calls

I've been using the Revealing Module pattern in my Javascript lately to help structure my code and everything has gone well. However, I'm a bit confused by this code snippet: function vm() { var pub = function () { alert("from pub: " +…
Roarster
  • 804
  • 1
  • 8
  • 13
2
votes
2 answers

Revealing Module Pattern with Angular

Today code is driving me mad again especially the Angular with the Revealing Module Pattern in an Angular service. When I started I saw nothing wrong with it... now apart from not working... I don't know. Any way know I want to know if it's angular…
wendellmva
  • 1,896
  • 1
  • 26
  • 33
2
votes
1 answer

Returning values from Javascript modules after ajax call

---EDITED---due to my ignorance, this is actually the same as alllll the other AJAX-type questions out there...need to get into the right mindset. Leaving it here for posterity's sake and maybe help others take a second look at callbacks before…
user
  • 4,651
  • 5
  • 32
  • 60
2
votes
2 answers

How do you namespace objects in the Revealing Prototype Pattern?

I've been using the Revealing Module pattern and have several namespaces. Example: // here's the namespace setup var myProject= myProject|| {}; var myProject.models= myProject.models || {}; myProject.models.MyModel= function(){ var someMethod =…
AlignedDev
  • 8,102
  • 9
  • 56
  • 91
2
votes
0 answers

Revealing module implicity calling an internal function - is this a "smell"

I'm trying to improve my javascript and have been using the revealing module pattern to good effect but I noticed that code in the module not in a function or the return is executed on creation have utilised this, such as: var MyModule = function…
Nathan
  • 931
  • 1
  • 12
  • 26
2
votes
1 answer

Javascript: Mixing constructor pattern and Revealing Module Pattern

Is there any way I can do have a Javascript class that extends an object that was created through the revealing module pattern? I tried the following code, but is there away to achieve the same thing? sv.MergeQuestionViewModel = function () { …
Abe
  • 6,386
  • 12
  • 46
  • 75
2
votes
2 answers

A good practice for protecting object literals and keeping them from being overwritten

I've been doing some research on object literals and such. I am creating a game that has various properties from my player. These prorpeties are stored in multiple groups, such as his ship and all the properties for that, his wepaon and all the…
klewis
  • 7,459
  • 15
  • 58
  • 102
2
votes
2 answers

Knockout.js: Function parameter undefined

I have a very simple example that is not working. jsfiddle: http://jsfiddle.net/ThomasDeutsch/8hzhp/3/ // My Model function Customer(id, name, lastname) { this.Id = ko.observable(id); this.Name = ko.observable(name); this.LastName =…
1
vote
1 answer

How to assign events in revealing prototype pattern?

I am trying to implement Revealing Module Pattern. I need to assign an event handler to one of elements, this event handler is a function I define in protoype but I get this.trigger is not a function error. Here's what I have done: //constructor var…
Ufuk Hacıoğulları
  • 37,978
  • 12
  • 114
  • 156
1
vote
2 answers

Why does the value of x is not updating ? is there anything wrong with the code ? i'm new to javascript

var ModuelPattern=(function () { var x="A" var change=function(){ if(x==="A"){ x="B" } else{ x="A" } } return{ x:x, f:change } })(); …