Variable Accessors in UnityScript (Get{} and Set{})

I am (finally) learning the nuances of the Singleton design pattern, and was wondering if there’s any way to use a variable accessor (get{} or set{}) in UnityScript.
The c# syntax is quite simple and can be found all over the internet, but no matter what I try, I can’t get it to work in JavaScript.

Here’s some (pseudo)code to turn a class called WhirldIn into a singleton hosted by a GameObject to enable certain methods it contains to yield. It would work fine if I used a static var called S to store the singleton reference and a static function to initialize the var, but it just seems so much cooler to call WhirldIn.S.Load and have the singleton initialize itself if necessary :slight_smile:

private static var s : WhirldIn = null;	//Static Singleton Reference
static function get S () : WhirldIn {	//Could be replaces with an init function
	if (s == null) {
	    Debug.Log("Initializing WhirldIn GameObject");
	    var go : GameObject = new GameObject();
	    s = go.AddComponent(WhirldIn);
	    go.name = "_WhirldIn";
	    DontDestroyOnLoad(go);	//Ensure the GameObject host of this Singleton class survives scene changes
	}
	return s;
}

Also, is there any practical overhead in always calling a .S accessor rather than just using a .S static var after initializing the singleton manually?

Here’s some relevant threads I have been able to find:

(Talks about a “get and set accessor in UnityScript”)

(C# Singletons)

http://forum.unity3d.com/threads/59621-Static-getter-setter
(Discussion on how to make this work - but the solution gives me compilation syntax errors)

From what i’ve heared it’s not possible to create static properties in UnityScript.

Read “Mike 3”'s answer on this question:

Edit : Fixed the link