在 ActionScript 3 中引用 getter/setter 函数

发布于 2024-08-05 15:32:55 字数 341 浏览 1 评论 0原文

如何获取 ActionScript 3 中 getter 和 setter 函数的引用?

如果在调用中定义了一个方法,例如,

public function blah():String { ...}

我只需说 blahthis.blah 即可获得对它的引用,

如何获得对

public function get blah2():String {}
public function set blah2(b:String):void {}

谢谢!

How does one get a reference the the getter and setter functions in actionscript 3?

if a method is defined on the calls, e.g.

public function blah():String { ...}

I can get a reference to it by just saying blah or this.blah

How do get a reference to

public function get blah2():String {}
public function set blah2(b:String):void {}

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

我偏爱纯白色 2024-08-12 15:32:55

原始回复:

不幸的是,您将无法将这些引用存储为函数。 getter 和 setter 方法实际上是围绕您不应该能够这样做的想法构建的,因此它们充当属性。

您是否需要专门引用这些函数?


我正在回复的评论:

我想根据自定义元数据标签动态添加外部接口方法,例如[External]。我能够对常规方法执行此操作,但我也尝试将其扩展到 getter/setter。为此,我需要动态获取对该函数的引用,以便我可以使用 apply 函数使用正确的参数执行它。

我认为在这种情况下你最好使用多步骤方法。由于 getter 和 setter 充当属性而不是方法,因此测试它是否是属性然后直接为其赋值是有意义的。你能用这个吗:

if( foo.blah2 is Function )
{
    foo.blah2.apply( foo, arr );
}
else
{
    foo.blah2 = arr[ 0 ];
}

Original response:

Unfortunately, you will not be able to store references to those as functions. The getter and setter methods are actually built around the idea that you shouldn't be able to and they therefore function as a property.

Is there a reason that you need to reference the functions specifically?


The comment I'm responding to:

I want to dynamically add external interface methods based on custom metadata tags, e.g. [External]. I was able to do this for the regular methods, but I'm trying to extend this to getter/setters as well. To do this, I need to get a reference to the function dynamically, so I can execute it with the right args using the apply function.

I think you're better off using a multi-step approach in that case. Since getters and setters function as a property and not a method, it would make sense to test to see if it is a property and then simply assign it a value directly. Would you be able to use this:

if( foo.blah2 is Function )
{
    foo.blah2.apply( foo, arr );
}
else
{
    foo.blah2 = arr[ 0 ];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文