Mascara: Next Generation JavaScript compiler

Try it Download Buy About Documentation Blog Contact

Constructors

A constructor may occur in a class definition. It is a special method which is called when the class is instantiated. It is defined like a method with the same name as the class.

Syntax definition [Help]
function classname ( [ parameters ] ) 
                     [ : [ initializers , ] 
                         [ super ( [ arguments ] ) ] ]
{
      [ statements ]
}

Example:

class A {
    var a : int;
    function A(x : int) : a=x, super() {}
}

Constructors does not have a return type like ordinary functions. Instead it may have a list of initializers and/or a super call.

Initializers are used to assign values to non-nullable properties, which is required to be initialized before the body of the constructor is executed.

X Try!
Mascara JavaScript Generated JavaScript

Translating...
Show compiler settings