Lack of operator overloading in ActionScript 3.0

后端 未结 2 625
温柔的废话
温柔的废话 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 04:03

    Yes it can be done (but be careful, its hacky): http://filimanjaro.com/2012/operators-overloading-in-as3-javascript-too-%E2%80%93-workaround/

    In the tutorial I wrote about +=, -= operator overloading. But it's also possible with ==, I can write more about that if it's not clear.

    Ah, the approach has some drawback (in rare cases it can be even dangerous). Think twice, before using it in a production.

    EDIT:

    After tests it seems the trick with +=, -= doesn't apply to == operator (what makes sense). Sorry for misleading info.

提交回复
热议问题