Skip to content

Instantly share code, notes, and snippets.

@rkatic
Created November 8, 2009 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rkatic/229188 to your computer and use it in GitHub Desktop.
Save rkatic/229188 to your computer and use it in GitHub Desktop.
jquery.isObject.js
(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);
@thinkt4nk
Copy link

what if the object's .toString is overridden?

@rkatic
Copy link
Author

rkatic commented Jun 14, 2012

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.

@thinkt4nk
Copy link

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