4DIS - JavascriptTutorial - Classes

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Text replace - "</javascript>" to "</syntaxhighlight>")
 
(8 intermediate revisions by 2 users not shown)
Line 7: Line 7:
 
'''Creating own classes :'''
 
'''Creating own classes :'''
  
<javascript>
+
<syntaxhighlight lang="javascript">
  
 
class MyClass
 
class MyClass
 
{
 
{
 +
    function MyClass ( ) { } // This is a constructor !
 +
   
 
     // ...
 
     // ...
 
}
 
}
  
</javascript>
+
// Variables...
  
 +
class MyClass
 +
{
 +
    function MyClass ( ) { }
 +
   
 +
    var a : int = 5;
 +
    var b : float = 2.5;
 +
}
  
<javascript>
+
// Functions...
  
 
class MyClass
 
class MyClass
 
{
 
{
     // ...
+
     function MyClass ( ) { }
 +
   
 +
    var a : float = 2.5;
 +
    var b : float = 7.5;
 +
   
 +
    function MyFunction ( )
 +
    {
 +
        return a * b;   
 +
    }
 +
}
 +
 
 +
</syntaxhighlight>
 +
 
 +
----
 +
 
 +
'''Using own classes :'''
 +
 
 +
<syntaxhighlight lang="javascript">
 +
 
 +
var mc : MyClass = new MyClass ( );
 +
 
 +
print ( mc.MyFunction ( ).ToString ( ) );
 +
 
 +
</syntaxhighlight>
 +
 
 +
----
 +
 
 +
'''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>
+
</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