Lack of operator overloading in ActionScript 3.0

后端 未结 2 626
温柔的废话
温柔的废话 2021-02-19 03:27

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 cl

2条回答
  •  别跟我提以往
    2021-02-19 03:57

    Nope.

    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 .

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

    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.

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

提交回复
热议问题