Does UnityScript support Object Literal syntax?

I heard that UnityScript is pretty close to JavaScript. Does UnityScript support Object Literal JavaScript syntax?

eg.

var x = { y: 12 }; 

Oddly, the google search for UnityScript "Object Literal" does not yield useful results.

+4
source share
1 answer

UnityScript and JavaScript have very different semantics.

Creating a new JavaScript file in Unity with this syntax will not compile.

 #pragma strict var x = { y: 12 // error: BCE0005 }; function Start () { Debug.Log (xy); // error: BCE0019 } 

This will result in build errors:

NewBehaviourScript (4,5): BCE0005: unknown identifier: 'y'.
NewBehaviourScript (8.17): BCE0019: 'y' is not a member of Boo.Lang.Hash.

However, you can implement a Hashtable :

 #pragma strict var x:Hashtable = new Hashtable(); x["y"] = 12; function Start () { Debug.Log (x["y"]); } 
+7
source

Source: https://habr.com/ru/post/1446130/


All Articles