views:

608

answers:

3

In Actionscript 3, why does getDefinitionByName() return an Object when the docs say:

Returns a reference to the class object of the class specified by the name parameter.

Based on that, I would conclude that the returned object should be Class instead of Object. Can someone enlighten me why that is not the case?

+6  A: 

Despite the method signature, getDefinitionByName does return Class. I think the misleading signature is due to the method existing before the Class object (when it used to return an anonymous/extended object instance).

Richard Szalay
+2  A: 

Perhaps Adobe considered that this function might return different values in a future version of Flash Player. For instance, ECMAScript, the standard on which ActionScript is based, has historically used Function objects with prototypes as the basis for class-like objects. During discussions of the newest versions of the ECMAScript standard, there has been sugestions for "freezing" function-based classes at run-time to make them into something like compile-time Class objects. What if you could also specify a definition name for them? Are they actually of type Class at this point, or are they still or type Function? Probably the later, in my opinion. Both 'Class' and 'Function' references can be generalized as Object, so that return type makes sense in this context.

Note: This explanation is purely speculation based on what I've read in the ECMAScript specification wiki and the blogs of various committee members.

joshtynjala
+4  A: 

getDefinitionByName can also return a Function, such as getDefinitionByName('flash.utils.getDefinitionByName'). This only works on namespace-level functions, though, not static class methods.

AaronOfTomorrow