引用的getter / setter函数在ActionScript 3 [英] Referencing getter/setter functions in actionscript 3

查看:108
本文介绍了引用的getter / setter函数在ActionScript 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个人如何在ActionScript 3中得到一个参考的getter和setter函数?

如果一个方法的调用定义的,例如

 公共职能胡说():字符串{...}
 

我可以只是说获得对它的引用等等 this.blah

如何获得引用

 公共职能得到blah2():字符串{}
公共功能集blah2(二:字符串):无效{}
 

谢谢!

解决方案

原始响应:

不幸的是,你将无法引用存储作为这些功能。 getter和setter方法​​实际上是建立在,你不应该是能够的想法,因此,他们作为一个属性。

有没有你需要引用的功能具体是什么原因呢?


注释我回答:

我想根据自定义元数据标签,如动态添加外部接口方法[外部]。我能做到这一点的常规方法,但我想这延伸到的getter / setter方法​​为好。要做到这一点,我需要一个引用函数动态,这样我就可以用正确的args使用应用函数执行它。

我觉得你最好使用在这种情况下,一个多步骤的方法。由于getter和setter作为属性,而不是一种方法,它会是有意义的测试,看它是否是一个属性,然后干脆直接给它分配一个值。您是否能够使用这样的:

 如果(foo.blah2是功能)
{
    foo.blah2.apply(FOO,ARR);
}
其他
{
    foo.blah2 =改编[0];
}
 

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!

解决方案

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 ];
}

这篇关于引用的getter / setter函数在ActionScript 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆