Re:Design patterns explained in Javascript
by jcampbell1 on Thursday July 14, 2011 @12:27PM
(#2763719)
I really think the module pattern is an anti-pattern. The positive benefits of public/private methods, are more than offset by the performance penalty of having each instance of the an object have it's own methods, rather than sharing through the prototype.
[ Parent
| on HN ]
My understanding (and the article reflects this) is that the "module pattern" generally refers to a function that is executed immediately after definition; ie: var module = (function() { ... })().
I'm guessing you're referring to Crockford's pattern (IIRC he calls it a "functional constructor" in JS:tGP), which is generally the same, but the function is instead executed when an object is instantiated with it.
It's a small distinction, but your drawbacks don't apply to the module pattern as I understand it, since the function is only executed once.
Re:Design patterns explained in Javascript
by jcampbell1 on Thursday July 14, 2011 @04:12PM
(#2764858)
You are quite right. The way he lays out the module pattern forces it to be a singleton.
Re:Design patterns explained in Javascript
by Androsynth on Thursday July 14, 2011 @01:13PM
(#2763904)
thats really application specific. In fact JS engines are so fast and browsers have so much memory nowadays that in the vast majority of JS applications, this is a non-issue.