- Home /
How do I create Javascript class?
I know classes are a deep subject but some basics would be good toknow here too..advantages, disadvantages etc.
Answer by Mike 3 · Aug 05, 2010 at 11:39 AM
Just to add to what Jashan said, heres how you actually declare a class in js:
class YourClassName
{
}
or
class YourClassName extends OtherClass
{
}
In Unity 3, you'll need to use implements instead of extends if you're implementing interfaces
Answer by jashan · Aug 05, 2010 at 11:33 AM
In fact, you are creating JavaScript classes whenever you are creating a script in Unity which uses JavaScript / UnityScript as implementation language. Those "scripts" are classes derived of MonoBehaviour (that's something that UnityScript/JavaScript hides from you - in C#, these things are much clearer ... you see that you create a class, and you also see which class the class is derived from).
Of course, in JavaScript, you could also create non-MonoBehaviour classes which could be used e.g. for plain data containers that should not be attached to any game objects.