I have created new objects with Dojo.declare. How to overload operator == for objects ?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
You can't. JavaScript doesn't support operator overloading.
You can't overload
==
, but==
has an implicit.toString()
call, so whatever.toString()
returns will allow you to effectively overload==
(kinda):As for how to do this in Dojo, I don't use Dojo, sorry, but the gist is that you get a reference to whatever object is creates and add
thatObject.prototype.toString
as in my example.You can't in Java/ECMAscript. You can only overload operators using ExtendScript from Adobe. See this example. Also see this blog entry (pro), or this (contra).