O'Reilly logo

haXe 2 by Benjamin Dasnois

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Constructing class instance

Constructing a class instance is done using the new keyword, as follows:

var user = new User("Benjamin");

In this example, we create an instance of the User class. Doing so calls the class' constructor. The class constructor is defined in the class as the public non-static new function. It may take any number of parameters. The following is an example of our User class:

class User
{
public function new(title : String, name : String)
{
//Do things
}
}

You can call the superclass's constructor by calling super() (with parameters if needed).

You can access the current class instance using the this keyword.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required