在 ActionScript 3 中引用 getter/setter 函数
如何获取 ActionScript 3 中 getter 和 setter 函数的引用?
如果在调用中定义了一个方法,例如,
public function blah():String { ...}
我只需说 blah
或 this.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 技术交流群。

原始回复:
不幸的是,您将无法将这些引用存储为函数。 getter 和 setter 方法实际上是围绕您不应该能够这样做的想法构建的,因此它们充当属性。
您是否需要专门引用这些函数?
我正在回复的评论:
我认为在这种情况下你最好使用多步骤方法。由于 getter 和 setter 充当属性而不是方法,因此测试它是否是属性然后直接为其赋值是有意义的。你能用这个吗:
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 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: