开发者

Singleton Class in JavaScript [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Simplest/Cleanest way to implement singleton in JavaScript?

  1. What is the use of Singleton class?
  2. 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}
  3. Any examples on how to create Singleton Class in JavaScript.


  1. 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.

  2. 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.

  3. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜