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
3
votes
1 answer
javascript: constructor function vs revealing module pattern for single use
I have come to understand that constructor functions can be instantiated to create new objects in javascript which has its own _proto_ property and also giving the property 'prototype' to the constructor function.
function MyController() {
var…

riju
- 203
- 2
- 8
3
votes
2 answers
Revealing module pattern naming convention
I'd like to avoid having to remember two names for a method, one for public and one for private access. In that sense, in which case would a script fail if you use same name for both? When would following code fail?
var TestClass = function() {
…

Nikola Radosavljević
- 6,871
- 32
- 44
3
votes
2 answers
Determining the scope of a 'Revealing Module Pattern' module with jQuery
Say I have this module and I want it to self initialize and attach to its scope. Like so:
(function( scope ) {
var Module = (function() {
return {
init: function(){
console.log('Initialized');
}
};
…

Kriem
- 8,666
- 16
- 72
- 120
2
votes
1 answer
Converting single file revealing module pattern javascript to multi-file using import
I am new to JS design patterns and have not used much of require or import. I have a single module which contains multiple functions and private variables, which is packaged into a module. Currently everything is in one file but splitting it into…

Coola
- 2,934
- 2
- 19
- 43
2
votes
1 answer
partial revealing module security question, default values in signature
Flubbing around the revealing module pattern with ES6 syntax, the state of default variables seems dependent on including the trailing () (invocation) on the function.
But, wondering about accessing those underscore variables in the body of the…

Tim Pozza
- 498
- 6
- 9
2
votes
2 answers
JavaScript Revealing Module pattern private variable state
I have recently started working on a JavaScript project and coming from Java world things seem, not surprisingly, weird at times.
I was implementing a simple module (Using revealing module pattern, afaik) which would provide config based on…

Konaras
- 573
- 6
- 14
2
votes
4 answers
Passing arguments into the revealing Module pattern in Javascript
How can you pass arguments to a function when implementing the Revealing module pattern in JavaScript. I have a module like this
var GlobalModule = (function() {
function consoleLog(textToOutput) {
console.log(textToOutput);
}
…

cross19xx
- 3,170
- 1
- 25
- 40
2
votes
1 answer
Revealing Module Pattern return value convention
If I have a module with lots of stuff like this:
My.Module = (function () {
function method1 () {}
function method2 () {}
...
function method99 () {}
return {
method1: method1,
method2: method2,
...
…

dodov
- 5,206
- 3
- 34
- 65
2
votes
1 answer
Javascript: Generic getter/setter for revealing module pattern
Basically what I am trying to do is write a re-useable getter/setter to expose variables using the module pattern
// the getter/setter
function pub (variable) {
return function (value) {
return (arguments.length ? variable = value :…

thedarklord47
- 3,183
- 3
- 26
- 55
2
votes
1 answer
Initialize subscriptions to ko.subscribable at module creation
I have ViewModels that are implemented using the Revealing Module Pattern. I am using global knockout subscribable to achieve decoupled passing of data between these. What i am doing now is, creating an instance of a ViewModel in a…

robbannn
- 5,001
- 1
- 32
- 47
2
votes
2 answers
Javascript revealing module pattern
I struggle to understand the advantages of the revealing module pattern.
Take f.e. the following code:
var Person = function(name){
this.name = name;
var priv = 'secret';
}
var OtherPerson = function(name){
var name = name;
var priv =…

Jannic Beck
- 2,385
- 21
- 30
2
votes
1 answer
Javascript Revealing Module Pattern in AngularJS Service not working
I'm using the following code in my angularJS service to get some task done :
angular.factory('promiseFactory', function(){
var artistIds = [];
function setArtistIds(artistIds){
artistIds = artistIds;
}
return {
…

Param Singh
- 1,325
- 3
- 13
- 28
2
votes
2 answers
Javascript promise not delaying function execution
I'm using ES6 javascript promises in Chrome and am having trouble understanding why the promise executed within the function _getStatus() is not returning the result argument in the success handler which would result in the alert box containing…

Vee
- 1,821
- 3
- 36
- 60
2
votes
1 answer
Is there a way to prototype a namespace in a limited scope?
I have a prototyped function that i would like to use it in a limited scope in order to provide it with a jquery plugin.
//Prototype
function StringBuilder(str) {
this.value = str;
}
StringBuilder.prototype.append = function (str) {
…

CodeArtist
- 5,534
- 8
- 40
- 65
2
votes
1 answer
How can I create an object of fixed structure?
I have the following code inside my revealing module, but I am uncertain with how to declare/define imageListItem, which is strictly a DTO and doesn't really require any information hiding. Am I correctly defining this object?
var imageListItem =…

ProfK
- 49,207
- 121
- 399
- 775