instanceof function on objects returned from jsdom window #424

Closed
ghost opened this Issue Mar 22, 2012 · 4 comments

Projects

None yet

2 participants

@ghost
ghost commented Mar 22, 2012

I don`t know so much if this is a bug. It is one of those things that makes sense the way it works but introduces some subtle issues into ones application.

When working with jQuery like the example suggests this pops up so it is worth noting in the docs. Objects jQuery return are of the type window.Array window.Object etc and not part of the Node prototype. For example window.$.map returns something that is a window.Array and not an actual Array.

Subtle difference but it could be a while before you notice these things running around you application are not actually Arrays, Objects etc.

I bet this pops up a million more places. I have been hacking at this for a while and it even caught me off guard. Again not so much a bug just a little fact that makes bugs.

:)

@domenic
Collaborator
domenic commented Oct 5, 2012

So if I am understanding this correctly, you have a jsdom window, but window.Array is undefined, so

window.$("div") instanceof window.Object

is false? Whereas

window.$("div") instanceof global.Object

is true?

If this is the exact problem, it should be easy to fix, by just hanging a few of the more obvious globals off of window.

@domenic domenic referenced this issue Dec 3, 2012
Closed

Set User-Agent #196

@domenic
Collaborator
domenic commented Jul 21, 2013

Upon further inspection, the current behavior is correct: we can't let changes to the Node globals interfere with the changes in a given window, or even worse, let changes in one window interfere with changes in another window (which would be the case if they all shared the Node globals).

@domenic domenic closed this Jul 21, 2013
@NStal
NStal commented Jul 27, 2013

It that means "Set User-Agent" won't be fixed?

@domenic
Collaborator
domenic commented Jul 27, 2013

@NStal I have no idea what you are asking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment