Skip to content

Commit 0fcfac7

Browse files
rafbmdmethvin
authored andcommitted
Refine the jQuery.isWindow check.
1 parent 166b9d2 commit 0fcfac7

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/core.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,8 @@ jQuery.extend({
476476
return jQuery.type(obj) === "array";
477477
},
478478

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

484483
isNumeric: function( obj ) {

test/unit/core.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,9 +558,10 @@ test("isXMLDoc - XML", function() {
558558
}
559559

560560
test("isWindow", function() {
561-
expect( 12 );
561+
expect( 14 );
562562

563563
ok( jQuery.isWindow(window), "window" );
564+
ok( jQuery.isWindow(document.getElementsByTagName("iframe")[0].contentWindow), "iframe.contentWindow" );
564565
ok( !jQuery.isWindow(), "empty" );
565566
ok( !jQuery.isWindow(null), "null" );
566567
ok( !jQuery.isWindow(undefined), "undefined" );
@@ -570,8 +571,7 @@ test("isWindow", function() {
570571
ok( !jQuery.isWindow(1), "number" );
571572
ok( !jQuery.isWindow(true), "boolean" );
572573
ok( !jQuery.isWindow({}), "object" );
573-
// HMMM
574-
// ok( !jQuery.isWindow({ setInterval: function(){} }), "fake window" );
574+
ok( !jQuery.isWindow({ setInterval: function(){} }), "fake window" );
575575
ok( !jQuery.isWindow(/window/), "regexp" );
576576
ok( !jQuery.isWindow(function(){}), "function" );
577577
});

0 commit comments

Comments
 (0)