Created
November 8, 2009 09:17
-
-
Save rkatic/229188 to your computer and use it in GitHub Desktop.
jquery.isObject.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(jQuery){ | |
var toString = Object.prototype.toString, | |
hasOwnProp = Object.prototype.hasOwnProperty; | |
jQuery.isObject = function( obj ) { | |
if ( toString.call(obj) !== "[object Object]" ) | |
return false; | |
//own properties are iterated firstly, | |
//so to speed up, we can test last one if it is not own | |
var key; | |
for ( key in obj ) {} | |
return !key || hasOwnProp.call( obj, key ); | |
} | |
})(jQuery); |
Overridden Object.prototype.toString
? That would be silly.
Please note that probably this code isn't what you want. It is outdated and updated one is integrated into jQuery core as jQuery.isPlainObject
since version 1.4.
Ah, my mistake. You're right, overriding the prototype's method would be silly. :P
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what if the object's .toString is overridden?