The shortest Singleton declaration!
public class Singleton {
static private var _instance:Singleton;
static public function getInstance():Singleton {
/// return _instance || ( _instance = new Singleton( new key() ) );
return _instance ||= new Singleton( new key ) ;
}
public function Singleton(singleton:key){}
}
class key{}
Thanks to John Lindquist for the fix, haha.
John Lindquist 3:48 PM on 29 April 2010 Permalink |
You can go shorter here:
return _instance || ( _instance = new Singleton( new key() ) );
to
return _instance ||= new Singleton( new key ) ;
from docs:
“||= logical OR assignment Assigns expression1 the value of expression1 || expression2.”
pablobandin 4:28 PM on 29 April 2010 Permalink |
NICE! that´s even better! i cant belive i missed that!