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.
Questions tagged [revealing-module-pattern]
179 questions
68
votes
4 answers
JavaScript design pattern: difference between module pattern and revealing module pattern?
I'm reading the book Learning JavaScript Design Patterns recently. What I don't get is the difference between module pattern and revealing module pattern. I feel they are the same thing. Anyone can give an example?

牛さん
- 2,884
- 3
- 29
- 43
55
votes
3 answers
Javascript return with colon
I am learning JavaScript and have come across of the structure below:
var Test = (function () {
function func1() {
//do something.....
}
function func2() {
//do something.....
}
function func3() {
//do something.....
…

Sean
- 981
- 1
- 9
- 19
18
votes
1 answer
Knockout.js mapping a JSON into an observable-array
I want to build a client for my REST-Service using Knockout.js.
I have a lot of Repositorys i want to access through different urls - so i came up with this solution using the Revealing-Prototype-Pattern.
My problem: I can not find out how to map…

Thomas Deutsch
- 2,344
- 2
- 27
- 36
17
votes
3 answers
Revealing Module Pattern with a constructor
I'm having a bit of trouble figuring out the best way to implement this.
I want a module that has a constructor that takes in an argument that stores it for later use within the module.
var ModuleB = function(moduleA) {
this.moduleA =…

Kyle Gobel
- 5,530
- 9
- 45
- 68
17
votes
4 answers
How can I view the outline in eclipse when using the revealing module pattern?
I'm currently refactoring some Javascript code we have and amongst other things I've changed it to make use of the revealing module pattern. The code is looking much tidier and it works fine but I can't see the functions anymore in the outline view.…

Ben Thurley
- 6,943
- 4
- 31
- 54
15
votes
5 answers
Creating Multiple Instances of a Module
I thought I was starting to understand JavaScript quite well but clearly not. Let me explain my problem with an example. First I have the following module defined:
var Test = function() {
var counter = 0;
function init() {
…

nfplee
- 7,643
- 12
- 63
- 124
14
votes
2 answers
The Revealing Module Pattern (RMP) disadvantages
I recently got familiar with the Revealing Module Pattern (RMP) and I've read quite a few articles about it.
It seems like a very good pattern and I would like to start using it in a big project. In the project I'm using : Jquery, KO, requireJS,…

Tomer
- 17,787
- 15
- 78
- 137
12
votes
3 answers
Expose private variables in Revealing Module Pattern
I'm trying to implement the Revealing Module Pattern but I'm unable to expose a modified private property.
var myRevealingModule = (function(){
var name = 'Diogo';
function setName () {
name = name + ' Cardoso';
}
return {
…

Diogo Cardoso
- 21,637
- 26
- 100
- 138
12
votes
4 answers
Module pattern- How to split the code for one module into different js files?
For the module pattern, I'm doing something like:
(function(namespace) {
// tons of code
// blabla
})(window.myGlobalNamespace);
How do I split the code? I can think of a few ways, like use a hierachy of namespaces, or expand the object…

Boyang
- 2,520
- 5
- 31
- 49
11
votes
3 answers
What is meant by "public function can't be overridden if a patch is necessary." in Addy's description of the Revealing Module Pattern?
A disadvantage of this pattern is that if a private function refers to a public function, that public function can't be overridden if a patch is necessary. This is because the private function will continue to refer to the private implementation…

gogogadgetinternet
- 5,719
- 4
- 24
- 28
7
votes
1 answer
Global variables shared amongst Javascript Modules
I have a script that I'd like to seperate out to multiple modules.
For example, putting all my mouse events in another module (mouseup, mousedown, etc).
I use a bunch of global variables to keep track of all of my objects on the screen. The mouse…

Gurnzbot
- 3,742
- 7
- 36
- 55
6
votes
3 answers
(Revealing) Module Pattern, public variables and return-statement
I'm trying to understand how public` properties in the (Revealing) Module Pattern work. An advantage pointed out by Carl Danley "The Revealing Module Pattern" is:
Explicitly defined public methods and variables which lead to increased…

lampshade
- 2,470
- 3
- 36
- 74
6
votes
3 answers
Javascript Revealing Module pattern - exposing initialization variables after function has returned
I’ve been using the Javascript Revealing Module pattern a lot and I like the clear separation it gives between the public interface and the internals. However I keep running into a situation which makes me wonder if my overall usage pattern is…

Tom W Hall
- 5,273
- 4
- 29
- 35
5
votes
2 answers
How does an IIFE's being called immediately prevent it from polluting global scope?
In a Udacity lesson on immediately invoked function expressions (regarding the provided code snippet) it says:
The function that is being returned closes over (i.e., captures) the
hi variable. This allows myFunction to maintain a private,…

nCardot
- 5,992
- 6
- 47
- 83
5
votes
1 answer
TypeScript code similar to Revealing Module Pattern structure
I want to convert some JavaScript code I've written into TypeScript. I'm rather new to TypeScript syntax and way of thinking, as a JavaScript developer.
What is giving me a headache is the hard time I've had to convert some piece of code that uses…

gdyrrahitis
- 5,598
- 3
- 23
- 37