Adding in a jQuery.type(obj) method (a simple map to using Object.prototype.toString.call). Fixes #3330.

This commit is contained in:
John Resig 2010-08-25 09:57:34 -07:00
parent 18dad47489
commit 94f35d0519

View file

@ -438,18 +438,22 @@ jQuery.extend({
// Since version 1.3, DOM methods and functions like alert // Since version 1.3, DOM methods and functions like alert
// aren't supported. They return false on IE (#2968). // aren't supported. They return false on IE (#2968).
isFunction: function( obj ) { isFunction: function( obj ) {
return toString.call(obj) === "[object Function]"; return jQuery.type(obj) === "function";
}, },
isArray: function( obj ) { isArray: function( obj ) {
return toString.call(obj) === "[object Array]"; return jQuery.type(obj) === "array";
},
type: function( obj ) {
return toString.call(obj).slice(8, -1).toLowerCase();
}, },
isPlainObject: function( obj ) { isPlainObject: function( obj ) {
// Must be an Object. // Must be an Object.
// Because of IE, we also have to check the presence of the constructor property. // Because of IE, we also have to check the presence of the constructor property.
// Make sure that DOM nodes and window objects don't pass through, as well // Make sure that DOM nodes and window objects don't pass through, as well
if ( !obj || toString.call(obj) !== "[object Object]" || obj.nodeType || obj.setInterval ) { if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || obj.setInterval ) {
return false; return false;
} }
@ -595,9 +599,9 @@ jQuery.extend({
// The extra typeof function check is to prevent crashes // The extra typeof function check is to prevent crashes
// in Safari 2 (See: #3039) // in Safari 2 (See: #3039)
// Tweaked logic slightly to handle Blackberry 4.7 RegExp issues #6930 // Tweaked logic slightly to handle Blackberry 4.7 RegExp issues #6930
var type = toString.call(array); var type = jQuery.type(array);
if ( array.length == null || type === "[object String]" || type === "[object Function]" || type === "[object RegExp]" || (typeof type !== "function" && array.setInterval) ) { if ( array.length == null || type === "string" || type === "function" || type === "regexp" || (typeof type !== "function" && array.setInterval) ) {
push.call( ret, array ); push.call( ret, array );
} else { } else {
jQuery.merge( ret, array ); jQuery.merge( ret, array );