在ActionScript 3.0缺乏运算符重载运算符、ActionScript

2023-09-08 13:29:38 作者:南风

的事情之一,我最想念的ActionScript中是缺乏操作符重载,特别是==。我有点变通解决此问题通过添加一个比较的方法来我的班,但是,这并不在很多情况下帮助,当你要使用的东西,像内置的字典等。

One of the things I miss the most in ActionScript is the lack of operator overloading, in particular ==. I kind of work around this issue by adding a "Compare" method to my classes, but that doesn't help in many cases, like when you want to use things like the built in Dictionary.

有没有可以解决这个问题的好办法?

Is there a good way to work around this problem?

推荐答案

都能跟得上。

但它不伤害增加等于方法,你自己的类。我尝试从来没有使用 == 比较对象时(这同样适用 === ,这是同样的事情为对象),因为它仅检查的的身份的。

But it doesn't hurt to add equals methods to your own classes. I try to never use == when comparing objects (the same goes for ===, which is the same thing for objects) since it only checks identity .

可悲的是所有在Flash和Flex的集合假设身份是需要平等的唯一措施。

Sadly all the collections in Flash and Flex assume that identity is the only measure of equality that is needed.

有提示Flex中,有人想要在同一时间,以缓解这个问题,但现在看来似乎被抛弃了:有一个被称作接口的