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

Time for action – Assigning to Dynamic variables


When you declare a variable as being Dynamic, you will be able to assign any value to it at compile time. So you can actually compile this code:

class DynamicTest
{
   public static function main()
   {
      var dynamicVar : Dynamic;
      dynamicVar = "Hello";
      dynamicVar = 123;
      dynamicVar = {name:"John", lastName : "Doe"};
      dynamicVar = new Array<String>();
   }
}

The compiler won't mind even though you are assigning values with different types to the same variable!