单例的写法有很多种,最恶心的是哪一种?
最近在看ROR,发现一强人写的单例..
package com
{
/**
* …
* @author v-jinweh
*/
public class SingletonExample
{
private var _ins:Object
public function SingletonExample()
{
throw new Error(“请不要这样来欺负我嘛”,9990);
}
public static function getIns():Object
{
return _ins ||= new Object();
// this line is equals to
//return ins = ins || new Object();
// and equals to
//if (_ins == null)
//{
//_ins = new Object()
//}
// return _ins
}
}
}