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
5
votes
1 answer
Revealing Module / Prototype Pattern
Until now, I used the Revealing Module Pattern to structure my Javascript, like so:
var module = (function() {
var privateVar;
// @public
function publicFunction( ) {
}
return {
…

mrksbnch
- 1,792
- 2
- 28
- 46
5
votes
5 answers
Why does the { position affects this Javascript code?
I spent a fair bit of time on this Javascript issue (you can tell I am a JS noob):
Take some well written Javascript code like this example of the Revealing Module Pattern:
Running it works fine. Then move the "{" to the next line (as a C# developer…

Rodney
- 5,417
- 7
- 54
- 98
5
votes
3 answers
Implementing AMD in JavaScript using RequireJS
I am totally new to RequireJS so I'm still trying to find my way around it. I had a project that was working perfectly fine, then I decided to use RequireJS so I messed it up :)
With that out of the way, I have a few questions about RequireJS and…

Kassem
- 8,116
- 17
- 75
- 116
4
votes
1 answer
Revealing module pattern combined with ES6 modules
I don't know which approach is better with ES6 modules and the revealing module pattern. Is the data / functionality from an ES6 module as private as an IIFE?
Should I just use *only ES6 modules, like so:
// Export file
export const test = () => {
…

Grecdev
- 899
- 9
- 14
4
votes
2 answers
How to write unit test for javascript revealing module pattern with Jest?
For example: my math_util.js is
var MathUtil = function(){
function add(a,b){
return a + b;
}
return {
add: add
};
}
I'll use Jest to test add(). So I'll write
test('add', ()=>{
expect(MathUtil().add(1,1)).toBe(2);
});
But I get…

Chanh
- 43
- 5
3
votes
2 answers
Why do we use self-executing functions in the revealing module pattern?
I've been actively using the revealing module pattern for years but there's a few things I'd like to understand deeper. From what I understand potential benefits of self-executing functions are anoymimty & self-execution, both of which don't seem…

williamsandonz
- 15,864
- 23
- 100
- 186
3
votes
1 answer