views:

66

answers:

2

When declaring a variable to have an open datatype, is there any difference, especially a performance difference, between typing a variable as a "wildcard" (i'm not sure of the official name for this) and typing a variable as an Object?

var myVar:*;

var myVar:Object;
+1  A: 

All variable and class types in ActionScript 3 are child classes of Object, so in terms of functionality, I don't think there is any difference between the two.

Some sub-classes of Object like int and Number behave like stack objects (this means that var firstInt:int = 5 and var secondInt:int = 5 actually point to the same Object), but that doesn't affect how they are treated when you point to them using a generic variable.

If I could hazard a guess, I'd say they added the wildcard as both a way to save typing and to make it easier for C/C++ migrants who are used to referencing generic types with a void* pointer rather than a base Object type.

Jengerer
+2  A: 

It wont affect performance. I use * when I dont know which type the Object will be until runtime.

From livedocs: use * under these circumstances:

  • When you want to defer type checking to runtime. You can use an untyped property or expression to circumvent compile-time type checking in strict mode. Note, however, that runtime type checking of assignment statements occurs whether you use strict mode or not.
  • When you want to store the value undefined in a property. Unlike previous versions of ActionScript, the value undefined is not a member of the Object data type. You must use an untyped property to store the value undefined.
daidai