Book Image

haXe 2 Beginner's Guide

5 (1)
Book Image

haXe 2 Beginner's Guide

5 (1)

Overview of this book

Table of Contents (21 chapters)
haxe 2
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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.