Kevin
Kevin

Reputation: 67

Return anonymous getter function in Flex / Actionscript?

Getter functions allow obj.meth syntax instead of obj.meth(), I'd like to create an anonymous one of these to return from another function. function get ():Object { } is invalid syntax. I don't suppose Flex offers an easy way to get this functionality, if it's even possible?

Upvotes: 1

Views: 331

Answers (2)

9re
9re

Reputation: 2428

You can override Object's default behavior by extending flash.utils.Proxy.

I made a very simple online code sample @ wonderfl.net
http://wonderfl.net/c/ngtC

I implemented 'setAnonymousGetter' to register an anonymous getter function.
In 'getProperty', if the property is an anonymous getter, executes 'apply' and return its result, otherwise returns the value of the property.

Upvotes: 4

JeffryHouser
JeffryHouser

Reputation: 39408

If I understand, you want to create an anonymous getter function? why? What possible purpose would this serve?

If you want to create properties on the fly, you can do use an Object or Dictionary:

myObject['newProperty'] = something;

The 'newProperty' could be anything you want including another variable.

Upvotes: 1

Related Questions