Skip navigation.

ASP.NET AJAX 1.0 Beta 2: Pseudo-Named FunctionsAll recent postsASP.NET AJAX 1.0 Beta 2: Basic DOM

Link Dump: JavaScript Singletons

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.

Comments

No comments yet

Emails and Notifications

Would you like to be notified when somebody responds to this post? 

TrackBacks

Sorry, TrackBacks are not allowed.

Submit your comment

Please enter only text since all HTML tags except hyperlinks will be stripped. Hyperlinks will become live links. Any comments with flaming or offensive language will be deleted. Be courteous to other posters. Thank you.

Your name (required):
Your email (optional):
Your site's URL (optional):
Enter this number
Type in the number above:
Comment (required):