AS3强制单例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AS3强制单例相关的知识,希望对你有一定的参考价值。
This implementation of the singleton pattern provides a way to enforce singleton usage. There are numerous Singleton implementations for AS3 (due to the lack of private constructor) this method, is the cleanest I've seen so far.
package mypackage { public class SingletonExample { public function SingletonExample(enforcer:SingletonEnforcer) { } private static var _instance : SingletonExample; public static function getInstance():SingletonExample { if (_instance == null) _instance = new SingletonExample(new SingletonEnforcer()); return _instance; } } } class SingletonEnforcer {}
以上是关于AS3强制单例的主要内容,如果未能解决你的问题,请参考以下文章