mirror of
https://github.com/jquery/jquery.git
synced 2026-01-24 04:28:05 -05:00
Refine the jQuery.isWindow check.
This commit is contained in:
committed by
Dave Methvin
parent
166b9d252a
commit
0fcfac7568
@@ -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 ) {
|
||||
|
||||
@@ -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" );
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user