4DIS - JavascriptTutorial - Classes

From Unify Community Wiki
Jump to: navigation, search

Javascript Classes

4DIS - JavascriptTutorial - Back


Creating own classes :

class MyClass
{
    function MyClass ( ) { } // This is a constructor !
 
    // ...
}
 
// Variables...
 
class MyClass
{
    function MyClass ( ) { }
 
    var a : int = 5;
    var b : float = 2.5;
}
 
// Functions...
 
class MyClass
{
    function MyClass ( ) { }
 
    var a : float = 2.5;
    var b : float = 7.5;
 
    function MyFunction ( )
    {
        return a * b;    
    }
}

Using own classes :

var mc : MyClass = new MyClass ( );
 
print ( mc.MyFunction ( ).ToString ( ) );

Static members :

class MyClass
{
    // You donĀ“t need a constructor here !
 
    static var a : float = 24.1;
    static var b : float = 2.5;
 
    static function MyFunction ( )
    {
        return a * b;
    }
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox