3 ms·
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 havin
by jcampbell1 15y ago
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.
- Androsynth 15y agothats 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.
- funksta 15y agoMy 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.
- jcampbell1 15y agoYou are quite right. The way he lays out the module pattern forces it to be a singleton.