From: Garrett Smith on
I'm confused about IE's evaluation of window == document.

IE:
window == document; // true
document == window; // false

I came across this while testing to see if an object is a window.

I need this so that in the registry cleanup for DOM events, that if the
object is window, then don't unregister callbacks. This works fine as
callbacks for window don't need cleanup, but it is also important as
removing unload callbacks before they fire will mean those callbacks
won't fire ever -- that's bad.

So I want to continue the loop if the object is window, but came across
this oddity. I am going to base my programming strategy around the
operands being in a certain side of == -- and I really don't like doing
that -- then at the very least I need a comment explaining why. I can't
explain it because I don't understand it. Somebody please fix that.
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/
From: Thomas 'PointedEars' Lahn on
Garrett Smith wrote:

> I'm confused about IE's evaluation of window == document.
>
> IE:
> window == document; // true
> document == window; // false

(I can confirm this for IE 6.0.2800.1106 / JScript 5.6.6626)

Well, those are references to host objects, and JScript is buggy there, too.
It works fine here (always `false') if you use `===' instead of `=='.


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
From: Stefan Weiss on
On 09/02/10 01:49, Garrett Smith wrote:
> I'm confused about IE's evaluation of window == document.
>
> IE:
> window == document; // true
> document == window; // false

I may be missing something, but don't you want both of these to evalute
to false? If so, Thomas's suggestion (using ===) should solve the
problem. If you're dealing with some weird edge case, a comment should
do it, IMHO. As if our code wasn't already riddled with "this is only
for IE compatibility" comments ;-)

I've never encountered this case, but I agree: it's definitely weird,
non-standard behavior. I wish there was a way to talk to the IE
developers, to ask them questions like this. With almost every other
browser, you could just look at the source code and see what's going on,
but IE is completely opaque. They don't even have a public bug tracker.


--
stefan
From: RobG on
On Feb 9, 10:49 am, Garrett Smith <dhtmlkitc...(a)gmail.com> wrote:
> I'm confused about IE's evaluation of window == document.
>
> IE:
> window == document; // true
> document == window; // false

Are you sure that *somewhere* in ECMA-262 it doesn't say that host
objects can change value depending on which side of an equality they
are on? Seems they have a get-out-of-jail-free card for every other
such circumstance.

If that was true, the spec was consistent and the same logic was
applied to identity and strict equality, would that help? ;-)


--
Rob
From: David Mark on
On Feb 8, 7:49 pm, Garrett Smith <dhtmlkitc...(a)gmail.com> wrote:
> I'm confused about IE's evaluation of window == document.
>
> IE:
> window == document; // true
> document == window; // false
>
> I came across this while testing to see if an object is a window.
>
> I need this so that in the registry cleanup for DOM events, that if the
> object is window, then don't unregister callbacks. This works fine as
> callbacks for window don't need cleanup, but it is also important as
> removing unload callbacks before they fire will mean those callbacks
> won't fire ever -- that's bad.

Will you please put that Kool-aid down? You don't need such cleanup
if you avoid the circular references we have discussed here ad
nauseam.

>
> So I want to continue the loop if the object is window, but came across
> this oddity. I am going to base my programming strategy around the
> operands being in a certain side of == -- and I really don't like doing
> that -- then at the very least I need a comment explaining why. I can't
> explain it because I don't understand it. Somebody please fix that.

No mystery. They are host objects, so they can do whatever they want.

You should change your design so that you do not have to differentiate
between windows and documents.