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 are of an unnamed type ("Anonymous Type"). They are made of a list of fields and their associated values. For example, here is how we can create one:

var obj = {id : 1, name : "Benjamin"};

Although the type of this object doesn't have a name, obj is still fully typed as {id :Int, name : String}. This is an anonymous type.

This is sometimes useful, if there is a type that you are not going to use a lot of time. By the way, this variable could be declared this way:

var obj : {id : Int, name : String};

Duck typing

Duck typing makes reference to an old cliché of "if it walks and talks like a duck, then it's a duck". In fact, we can use anonymous types to say that we want something that has at least ...

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