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

Anonymous objects

Anonymous objects are objects that you create on the fly using brackets. The following is an example:

{ age : 12, name : "Benjamin" };

This object, despite not being created from any class, is typed. Its type is: {age :Int, name : String}.

The following is an example that you can run:

class TesthaXe
{
public static function main(): Void
{
var user = {name : "Benjamin", age:12};
neko.Lib.println("User " + user.name + " is " + user.age + " years old.");
}
}

This program will print User Benjamin is 12 years old.

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