4DIS - JavascriptTutorial - Classes

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Text replace - "<javascript>" to "<syntaxhighlight lang="javascript">")
m (Text replace - "</javascript>" to "</syntaxhighlight>")
 
Line 41: Line 41:
 
}
 
}
  
</javascript>
+
</syntaxhighlight>
  
 
----
 
----
Line 53: Line 53:
 
print ( mc.MyFunction ( ).ToString ( ) );
 
print ( mc.MyFunction ( ).ToString ( ) );
  
</javascript>
+
</syntaxhighlight>
  
 
----
 
----
Line 74: Line 74:
 
}
 
}
  
</javascript>
+
</syntaxhighlight>

Latest revision as of 20:52, 10 January 2012

[edit] 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