- Home /
hot to make classes and why ?
how can i make class inside JS file ? and why i had to make a class ? i used to work without making classes from several years but i found i had to know little about that instead of ignoring it. i need to know the main form of it & a clear example , because i found lots of answers but it makes me confused little a bit .
thanks Muhammad
Answer by syclamoth · Feb 16, 2012 at 05:58 AM
Well, for starters, every JS file you make is a class. The compiler automatically wraps the content of the file in the correct bits to make it work.
If you want to create a seperate class within that (for example, if you want to organise variables in a more sensible fashion), you use this syntax-
class MyClassName{
var anInteger : int;
var aBoolean : boolean;
var aFloat : float;
function DoSomething : float
{
return aFloat + anInteger;
}
}
Then, to use this in your script, make an instance like this-
var anObject : MyClassName;
Your answer
Follow this Question
Related Questions
Custom JS class error - function is not a member of the class 2 Answers
Multiple classes inside each other 1 Answer
Access a script that has NO class? 2 Answers
Accessing a variable inside a class inside other script... 2 Answers
Linking prefabs to classes that are not attatched to gameobjects 1 Answer