Link Dump: JavaScript Singletons

Posted on November 15, 2006  |  

Posted in Development

No comments yet

A couple of links to posts and articles demonstrating the Singleton pattern in JavaScript:

I noticed people create JS Singletons either via new function(){...} or function (){...}(); Douglas Crockford makes an interesting point about it at the Yahoo! UI blog:

By using new to invoke the function, the object holds onto a worthless prototype object. That wastes memory with no offsetting advantage. If we do not use the new, we don’t keep the wasted prototype object in the chain. So instead we will invoke the factory function the right way, using ().

I feel like I’m putting lipstick on a pig, because this is anything but the canonical Singleton as we know it.