4DIS - JavascriptTutorial - Classes

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
Line 52: Line 52:
  
 
print ( mc.MyFunction ( ).ToString ( ) );
 
print ( mc.MyFunction ( ).ToString ( ) );
 +
 +
</javascript>
 +
 +
----
 +
 +
'''Static members :'''
 +
 +
<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>
 
</javascript>

Revision as of 09:04, 30 October 2011

Javascript Classes

4DIS - JavascriptTutorial - Back


Creating own classes :

<javascript>

class MyClass {

   function MyClass ( ) { }
   
   // ...

}

// 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 :

<javascript>

var mc : MyClass = new MyClass ( );

print ( mc.MyFunction ( ).ToString ( ) );

</javascript>


Static members :

<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