Skip to content

Comment on Design patterns explained in Javascript parent

Comments

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.

You are quite right. The way he lays out the module pattern forces it to be a singleton.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.