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

Scott J. Miles sjmiles at turbophp.com
Fri Sep 2 17:17:08 CDT 2005


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

Please note that the function I referenced in fact does *not* work correctly
because the == operator always returns false. 

>> 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. <<

Well, as I read this:

>> If the types of the two expressions are different, attempt to convert
them to string, number, or Boolean.  <<

Both operands are 'object' so no conversion is applied.

>> Values are considered equal if they are ... the same object <<

Two URI objects that specify the same path but that are different objects
are not ==.

I had to change the code from

if(doc.styleSheets[i].href &&	URI == new
dojo.uri.Uri(doc.styleSheets[i].href)) { return; }

to

if(doc.styleSheets[i].href &&	URI.toString() == new
dojo.uri.Uri(doc.styleSheets[i].href).toString()) { return; }

for correct results.

Regards,
Scott
________________________________________
From: NG-DHTML-bounces at netwindows.org
[mailto:NG-DHTML-bounces at netwindows.org] On Behalf Of Tom Trenka
Sent: Friday, September 02, 2005 2:43 PM
To: the Dojo project contributor's discussion list
Subject: [spam] Re: [ng-dhtml] comparing dojo.uri.Uri objects
anddojo.xml.htmlUtil.insertCssFile bug (?)

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
equal. 

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).

trt

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
 




More information about the NG-DHTML mailing list