In C# there are extension methods that can be written such as:
As I have been trying some C#/JS since I asked the question, it appears that JS does not recognize the extensions I wrote in C#. I placed the extensions in Standard Assets folder so that it would compile before the JS. That leaves me to think there isn't any way in JS to use extension methods and as such there is no way to write extension methods in JS, at least not for the present.
Since no other answers have been posted and I haven't been able to find any solution through my own fiddling, I draw the conclusion that it's a simple case;
answered Dec 17, 2010 at 03:58 PM
There are no extension methods in JS, or in Unity's version of JS (which isn't traditional JS).
JS won't recognize C# extension methods because C# extension methods are not real artefacts added to the class, they are syntactic sugar. In essence they are just static methods. The C# compiler, as a feature of the language, knows how to "use" them from an object context given the right syntax. But as said - it's just a bit of magic, they are not real. Hence they are not visible as more than static methods from a cross-language point of view.
Generally speaking, if you want a "quick and easy" language to program in, use JS. If you come from a "heavier" computing background and would like to have the full power of a strong mainstream language at your disposal, use C#. For larger projects I'd recommend C#.
Either way don't expect to get the same from both languages, they are different.
answered Oct 22, 2011 at 05:06 PM