x


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.

more ▼

asked Aug 05 '10 at 11:03 AM

Grimmy gravatar image

Grimmy
533 58 64 69

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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

more ▼

answered Aug 05 '10 at 11:39 AM

Mike 3 gravatar image

Mike 3
30.5k 10 65 252

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Aug 05 '10 at 11:33 AM

jashan gravatar image

jashan
10.1k 25 40 116

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3443
x336

asked: Aug 05 '10 at 11:03 AM

Seen: 7529 times

Last Updated: Apr 07 at 03:28 AM