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
1
vote
0 answers

How to convert Reveal Module Pattern in JavaScript to Typescript when function is taking global as argument

I am rewriting(code refactoring) the Javascript code into Typescript. I face a problem when converting reveal module Pattern into typescript namespace. The only thing that I don't understand is the role of global here. I really don't know what this…
1
vote
1 answer

callback function returning undefined

I'm trying to return an object inside a callback function In the following situation, the console.log() show the result as expected var dVizModule = (function(){ let dataset; function loadData(fileName) { dataset = d3.csv(fileName,…
1
vote
1 answer

ES5 Module pattern usage

Could you explain to me what is the difference between that two approaches (FirstModule and SecondModule: var MyModule = (function () { return { method: function () { console.log("MyModule:method"); } } })(); var…
Dizip
  • 85
  • 7
1
vote
0 answers

What's the benefit to storing data on a revealing module pattern module object rather than as a variable within the module?

I'm refactoring some legacy code that uses the revealing module pattern and there are instances of data being stored on the module which are then referenced later within the module's code. It seems like simply storing the data within the module…
1
vote
1 answer

javascript revealing module pattern with multiple files/modules and global vars

I apologize if this has been asked elsewhere, but all the info I've seen doesn't really help me understand both the answer and best practice. I'm attempting to use the revealing module pattern for javascript. I have a base js file that contains…
hyphen
  • 2,368
  • 5
  • 28
  • 59
1
vote
2 answers

Babelifying JavaScript Module Pattern with ES6 Arrow Functions

Babel is choking on code that uses the module pattern with an arrow function. If I try to process a file which reads: const lib = (() => { function sum(a, b) { return a + b; } function mult(a, b) { return a * b; } return { sum, mult …
1
vote
1 answer

Make imported code run only in specific page [Module Pattern + ES6]

I'm developing a code structure with import/export from ES6 using the module pattern. So in a file I have: // Product.js const Product = (function product() { const productJson = skuJson; const productTabs =…
1
vote
0 answers

How to implement 'ES6 imports' in es5 with module pattern

i wrote 3 modules ( Model, View, Controller ) with pure JS syntax. I mean like that: var Model = (function () { //... })(); var View = (function () { //... })(); var Controller = (function (model, view) { //do the job... })(Model,…
1
vote
1 answer

How to call a public method of one JS module into another, using the Revealing Module Pattern?

I've been experimenting with Javascript's Revealing Module Pattern, but I don't quite understand if and how I can call a public method of one module into another. Suppose I have these two modules (code is simplified): 1) Module A var lazyload = (…
grazdev
  • 1,082
  • 2
  • 15
  • 37
1
vote
0 answers

Why can't I use my JS revealing module function inside another module?

I am working on a project in JavaScript where I am writing my code in separate files using the revealing module pattern. I am also utilizing Gulp to concat those files together into one app.js file. The issue I am having is when I am trying to use…
cjh193
  • 309
  • 2
  • 3
  • 9
1
vote
1 answer

Javascript: Self invoking singleton function vs creating instances of the function?

Which one is better to implement in revealing modular pattern in javascript: Having a self invoking function which will get intialized just once at the time JS gets rendered, like this: