The official underscore.js uses this checkprovides the following method to find out if something is really an object:
// Is a given variable an object?
_.isObject = function(obj) {
return obj === Object(obj);
};
UPDATE
The updated underscore.js library is now using the following, becauseBecause of a previous bug in V8 and minor micro speed optimization., the method looks as follows since underscore.js 1.7.0 (August 2014):
// Is a given variable an object?
_.isObject = function(obj) {
var type = typeof obj;
return type === 'function' || type === 'object' && !!obj;
};