Mascara JavaScript compiler

Try it Download Buy About Documentation Blog Contact

Static members

Static members are members which belong to a class rather than an instance. They are declared with the attribute static.

class A {
    static function f() {} // static function
    static var x = 100; // static field
}

Static members are accessed by prefixing with the class name:

   A.f();
   A.x = 1001;

The class name can be left out when static members are accessed from inside the same class where they are defined:

class A {
    static var x = 100;
    static function() {
        x = 1001;
    }

A static constructor is a block with the static prefix which is executed only once, when the class is defined:

class A {
    static var x : Number;
    static {
        x = 1001;
    }

Static members can have the access modifiers public or private.