Actionscript-3 原型继承

发布于 2024-09-19 02:04:49 字数 304 浏览 9 评论 0原文

基本上,我想修改对象的构造函数
班级。由于每个类都扩展了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初熏 2024-09-26 02:04:49

您在什么情况下编码?
如果您使用的是 Flex 编译器 MXMLC(默认情况下,如果您使用的是 FlashBuilder),那么您可以添加编译器选项 -es。这应该会让 AS3 感觉更像 AS2 和 JS 并且支持原型链继承。

-compiler.es alias -es

“使用 ECMAScript 第 3 版基于原型的对象模型来允许动态覆盖原型属性。在基于原型的对象模型中,内置函数被实现为原型对象的动态属性。(高级)”

我不知道这是否有效以及 Adob​​e 添加到 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.

-compiler.es alias -es

"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.

水水月牙 2024-09-26 02:04:49

我不认为这在 AS-3 中是可能的,但在 AS-2 中却是可能的。

I don't think it's possible in AS-3, but it was in AS-2.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文