为什么从 getDefinitionByName() 返回对象?
在 Actionscript 3 中,为什么 getDefinitionByName() 返回一个对象,当文档说:
返回对 name 参数指定的类的类对象的引用。
基于此,我得出结论,返回的对象应该是 Class 而不是 Object。 有人可以告诉我为什么情况并非如此吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
getDefinitionByName 还可以返回 Function,例如 getDefinitionByName('flash.utils.getDefinitionByName')。
但这仅适用于命名空间级别的函数,不适用于静态类方法。
getDefinitionByName can also return a Function, such as getDefinitionByName('flash.utils.getDefinitionByName').
This only works on namespace-level functions, though, not static class methods.
尽管有方法签名,getDefinitionByName 确实返回 Class。 我认为误导性签名是由于 Class 对象之前存在的方法(当它用于返回匿名/扩展对象实例时)。
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).
也许 Adobe 认为该函数在 Flash Player 的未来版本中可能会返回不同的值。 例如,ActionScript 所基于的标准 ECMAScript 历史上一直使用带有原型的 Function 对象作为类对象的基础。 在讨论最新版本的 ECMAScript 标准时,有人建议在运行时“冻结”基于函数的类,使它们成为类似于编译时
Class
对象的东西。 如果您还可以为它们指定定义名称怎么办? 此时它们实际上是Class
类型,还是仍然是Function
类型? 在我看来,可能是后者。 “类”和“函数”引用都可以概括为Object
,因此返回类型在此上下文中有意义。注意:这个解释纯粹是基于我在 ECMAScript 规范 wiki 中读到的内容的推测各个委员会成员的博客。
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-timeClass
objects. What if you could also specify a definition name for them? Are they actually of typeClass
at this point, or are they still or typeFunction
? Probably the later, in my opinion. Both 'Class' and 'Function' references can be generalized asObject
, 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.