Skip to content

Commit

Permalink
Refine the jQuery.isWindow check.
Browse files Browse the repository at this point in the history
  • Loading branch information
rafbm authored and dmethvin committed Dec 6, 2011
1 parent 166b9d2 commit 0fcfac7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,8 @@ jQuery.extend({
return jQuery.type(obj) === "array";
},

// A crude way of determining if an object is a window
isWindow: function( obj ) {
return obj && typeof obj === "object" && "setInterval" in obj;
return obj != null && obj == obj.window;
},

isNumeric: function( obj ) {
Expand Down
6 changes: 3 additions & 3 deletions test/unit/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,10 @@ test("isXMLDoc - XML", function() {
}

test("isWindow", function() {
expect( 12 );
expect( 14 );

ok( jQuery.isWindow(window), "window" );
ok( jQuery.isWindow(document.getElementsByTagName("iframe")[0].contentWindow), "iframe.contentWindow" );
ok( !jQuery.isWindow(), "empty" );
ok( !jQuery.isWindow(null), "null" );
ok( !jQuery.isWindow(undefined), "undefined" );
Expand All @@ -570,8 +571,7 @@ test("isWindow", function() {
ok( !jQuery.isWindow(1), "number" );
ok( !jQuery.isWindow(true), "boolean" );
ok( !jQuery.isWindow({}), "object" );
// HMMM
// ok( !jQuery.isWindow({ setInterval: function(){} }), "fake window" );
ok( !jQuery.isWindow({ setInterval: function(){} }), "fake window" );
ok( !jQuery.isWindow(/window/), "regexp" );
ok( !jQuery.isWindow(function(){}), "function" );
});
Expand Down

0 comments on commit 0fcfac7

Please sign in to comment.