- Home /
anonymous functions with JavaScript?
are anonymous functions allowed in Unity? if not, why not?
is just tried to run the following simple script:
(function() { Debug.Log("blub"); })();
Answer by KvanteTore · May 03, 2010 at 09:45 PM
No, anonymous functions or closures does not work in in Unity Javascript. It is not really javascript, but rather a close syntactic cousin. It compiles down to CLR 2.0, which comes from a time before the DLR and with limited dynamic typing support. Duck-typing and the object <=> dict equivalence found in javascript is not supported either. All in all, I'd say it is probably closer to C# 2.0 than javascript.
This question and some of the comments therein are slightly related: http://answers.unity3d.com/questions/44/is-there-a-performance-difference-between-unitys-javascript-and-c
Answer by Eric5h5 · Oct 24, 2010 at 10:55 PM
Anonymous functions are allowed in Javascript with Unity 3.0.
how do you declare an anonymous function in Unity without getting errors?