Why is object returned from getDefinitionByName()?
-
03-07-2019 - |
Question
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?
Solution
getDefinitionByName can also return a Function, such as getDefinitionByName('flash.utils.getDefinitionByName'). This only works on namespace-level functions, though, not static class methods.
OTHER TIPS
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).
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.