Actionscript-3 原型继承
基本上,我想修改对象的构造函数
班级。由于每个类都扩展了 Object,我希望无论何时
任何类的对象被实例化后,修改后的函数都会
称为。
所以我这样做了:
Object.prototype.constructor = function (){
trace("it was called;");
};
并在跟踪语句上放置了一个断点。
但事情并没有就此停止。
跟踪语句也没有被执行。
有什么解决方案/建议吗?
Basically, I want to modify the constructor of the Object
class. Since every class extends Object, I hope whenever any
object of any class is instantiated, the modified function will
be called.
So I did this :
Object.prototype.constructor = function (){
trace("it was called;");
};
and put a breakpoint on the trace statement.
But it didn't stop there.
The trace statement did not get executed also.
Any solutions/suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在什么情况下编码?
如果您使用的是 Flex 编译器 MXMLC(默认情况下,如果您使用的是 FlashBuilder),那么您可以添加编译器选项 -es。这应该会让 AS3 感觉更像 AS2 和 JS 并且支持原型链继承。
“使用 ECMAScript 第 3 版基于原型的对象模型来允许动态覆盖原型属性。在基于原型的对象模型中,内置函数被实现为原型对象的动态属性。(高级)”
我不知道这是否有效以及 Adobe 添加到 ECMA Script 标准的所有扩展,例如包、命名空间和类。但你可以尝试一下。
In which context are you coding?
If you're using the Flex Compiler MXMLC (default, if you're in FlashBuilder), than you could add the compiler option -es. This should make AS3 feel more like AS2 and JS and support the prototype chain inheritance.
"use the ECMAScript edition 3 prototype based object model to allow dynamic overriding of prototype properties. In the prototype based object model built-in functions are implemented as dynamic properties of prototype objects. (advanced)"
I don't know, if this plays well with all the extensions Adobe added to the ECMA Script standard, like packages, namespaces and classes. But you could give it a try.
我不认为这在 AS-3 中是可能的,但在 AS-2 中却是可能的。
I don't think it's possible in AS-3, but it was in AS-2.