本文介绍了在ActionScript 3.0缺乏运算符重载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的事情之一,我最想念的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中,有人想要在同一时间,以缓解这个问题,但现在看来似乎被抛弃了:有一个被称作接口的和它被提到的的Flex开发指南的,但是它没有在任何地方使用。甚至不是在Flex集合使用它来确定平等。而且,由于你所要求的对Flash的解决方案,它可能没有反正帮你。

There are hints in Flex that someone wanted to alleviate this problem at one time, but it seems like it was abandoned: there is an interface called IUID, and it is mentioned in the Flex Developer's Guide , but it is not used anywhere. Not even the collections in Flex use it to determine equality. And since you are asking for a solution for Flash, it may not have helped you anyway.

我已经写了一些有关本(Flex中的上下文中)在我的博客:的。

I've written some more about this (in the context of Flex) on my blog: Is there no equality?.

这篇关于在ActionScript 3.0缺乏运算符重载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 15:41