Revealing module pattern instantiation and naming convention

108 views Asked by At

In examples of Revealing Module Pattern it is commonly used with Immediately Invoked Function Expression like so:

var foo = (function () { 
  ..rmp definition ... 
})(); 

to create an instance of the module right after definition. So my question is: is there anything about RMP that should discourage us from defining it in one place and then instantiating it later, possibly more than once? Like so:

var foo = function () { 
  ..rmp definition ... 
};
...
...
var foo1 = foo();
var foo2 = foo();

JSHint made me wonder cause I used to capitalize 'foo' and got warnings that it's not a constructor function (which is true) so it shouldn't start with upper case. So my second question is, what naming convention is advisable for a variable storing module definition to be used later?

P.S. I know that RMP is considered by some to be an antipattern, but that's not what I'm asking about. We could be talking about regular Module Pattern as well.

0

There are 0 answers