[ng-dhtml] comparing dojo.uri.Uri objects and dojo.xml.htmlUtil.insertCssFile bug (?)

Tom Trenka ttrenka at gmail.com
Fri Sep 2 16:42:48 CDT 2005

Speaking *very* quickly here, and not having actually tested this 
extensively (but having done some work in this area to try to see if I can 
trick JS into some version of operator overloading)...I *think* that it 
depends on what is returned from either .valueOf or .toString, as opposed to 
comparing the object directly.

It's interesting because you bring up a topic that I was about to start 
hitting again pretty hard for other purposes...and maybe should be tried?

Anyways. A quick look at some docs say this:

Equality (==, !=) 

   - If the types of the two expressions are different, attempt to 
   convert them to string, number, or Boolean. 
   - NaN is not equal to anything including itself. 
   - Negative zero equals positive zero. 
   - null equals both null and undefined. 
   - Values are considered equal if they are identical strings, 
   numerically equivalent numbers, the same object, identical Boolean values, 
   or (if different types) they can be coerced into one of these situations. 

Identity (===, !==) 

   - These operators behave identically to the equality operators except 
   no type conversion is done, and the types must be the same to be considered 

These are from the JScript documentation (which I happen to have very 
handy), but IIRC that's straight from the spec as well.

What it means is that at least one major JS engine tries to coerce each 
operand first, so if there is a toString method defined, that will probably 
be used. (Note that it doesn't say what order those tests are made, you'll 
have to look at the spec for that).

Anyways...that's why it works, and you shouldn't need to worry about it :)

(btw, IIRC if you are comparing 2 references that usually works just fine as 
well; it's pretty rare when you need the full === functionality).


On 9/2/05, Scott J. Miles <sjmiles at turbophp.com> wrote:
> In dojo.xml.htmlUtil.insertCssFile two dojo.uri.Uri objects are compared
> with '==' which I believe is incorrect. That operator compares the object
> reference addresses, yes?
> What is the preferred way to compare dojo.uri.Uri objects?
> UriA.toString() == UriB.toString()?
> Regards,
> Scott
> --
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.344 / Virus Database: 267.10.18/89 - Release Date: 9/2/2005
> _______________________________________________
> NG-DHTML mailing list
> NG-DHTML at netwindows.org
> http://netwindows.org/mailman/listinfo/ng-dhtml_netwindows.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://netwindows.org/pipermail/ng-dhtml_netwindows.org/attachments/20050902/9d5e8fad/attachment.htm

More information about the NG-DHTML mailing list