4DIS - JavascriptTutorial - Classes

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Text replace - "<javascript>" to "<syntaxhighlight lang="javascript">")
Line 7: Line 7:
 
'''Creating own classes :'''
 
'''Creating own classes :'''
  
<javascript>
+
<syntaxhighlight lang="javascript">
  
 
class MyClass
 
class MyClass
Line 47: Line 47:
 
'''Using own classes :'''
 
'''Using own classes :'''
  
<javascript>
+
<syntaxhighlight lang="javascript">
  
 
var mc : MyClass = new MyClass ( );
 
var mc : MyClass = new MyClass ( );
Line 59: Line 59:
 
'''Static members :'''
 
'''Static members :'''
  
<javascript>
+
<syntaxhighlight lang="javascript">
  
 
class MyClass
 
class MyClass

Revision as of 20:47, 10 January 2012

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;    
    }
}
 
</javascript>
 
----
 
'''Using own classes :'''
 
<syntaxhighlight lang="javascript">
 
var mc : MyClass = new MyClass ( );
 
print ( mc.MyFunction ( ).ToString ( ) );
 
</javascript>
 
----
 
'''Static members :'''
 
<syntaxhighlight lang="javascript">
 
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;
    }
}
 
</javascript>
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox