Reputation: 1195
Isn't the literal object instantiation in javascript a singleton?
Of course there is no "self" instantiation if the object is not found, but there is only one "copy" of the object kept around.
what are your thoughts?
Upvotes: 5
Views: 1136
Reputation: 1195
I found the answer in the article:
http://addyosmani.com/resources/essentialjsdesignpatterns/book/#singletonpatternjavascript
Singletons differ from static classes (or objects) as we can delay their initialization, generally because they require some information that may not be available during initialization time. They don't provide a way for code that is unaware of a previous reference to them to easily retrieve them. This is because it is neither the object or "class" that's returned by a Singleton, it's a structure. Think of how closured variables aren't actually closures - the function scope that provides the closure is the closure.
Upvotes: 2