Possible Duplicate:
Simplest/Cleanest way to implement singleton in JavaScript?
- What is the use of Singleton class?
- Can anyone give me a scenario where
Singleton class be applied?
{ If i am developing an Mobile App using JavaScript, what could be my Singleton Class here 开发者_如何学JAVA}
- Any examples on how to create Singleton Class in JavaScript.
A class implements the Singleton pattern when it is desired that there should only be one instance of that class extant at any given time.
The example that I'm most familiar with is if you are, for example, creating a game and you only want one player-controlled entity to exist at a time; the player entity would use the Singleton pattern.
Actually using Singletons in Javascript is kind of wonky, but Dynamic's link above makes sense.
Its useful when you want to share an object across classes.
精彩评论