In C# there are extension methods that can be written such as:
// Create an extension for string
public static class MyExtension
public static bool IsCaptialized(this string value)
// And then use it
string shouldBeCapitalized = "Capitalized";
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.
Answer by Statement
Dec 17, 2010 at 03:58 PM
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;
Same conclusion I came to when I answered the same question two weeks ago
I'm sorry, I didn't notice any other answers here? Or is this a duplicate question?
Answer by amirabiri
Oct 22, 2011 at 05:06 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.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users post good questions and use the site effectively we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
1 Person is following this question.
Reverse animation at the point it stopped playing
Is there eval() for C#?