diff options
author | RafaC3ABl Blais Masson <rafbmasson@gmail.com> | 2011-12-06 16:17:09 -0500 |
---|---|---|
committer | Dave Methvin <dave.methvin@gmail.com> | 2011-12-06 16:17:09 -0500 |
commit | 0fcfac7568823a4eec4e5dd7b9bf527a8ec04f5c (patch) | |
tree | e53f37873f6f700ad0f73022b07931c7c7db6b00 | |
parent | 166b9d252a025009413eee1584dc364996dcb1c2 (diff) | |
download | jquery-0fcfac7568823a4eec4e5dd7b9bf527a8ec04f5c.tar.gz jquery-0fcfac7568823a4eec4e5dd7b9bf527a8ec04f5c.zip |
Refine the jQuery.isWindow check.
-rw-r--r-- | src/core.js | 3 | ||||
-rw-r--r-- | test/unit/core.js | 6 |
2 files changed, 4 insertions, 5 deletions
diff --git a/src/core.js b/src/core.js index 1a029814f..9a551446b 100644 --- a/src/core.js +++ b/src/core.js @@ -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 ) { diff --git a/test/unit/core.js b/test/unit/core.js index d8906b89f..214b7ca5e 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -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" ); @@ -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" ); }); |