Skip to content

Instantly share code, notes, and snippets.

@cyan33
Last active October 29, 2017 01:30
Show Gist options
  • Save cyan33/3b6c27490b5db4296d82b451c9fa38c6 to your computer and use it in GitHub Desktop.
Save cyan33/3b6c27490b5db4296d82b451c9fa38c6 to your computer and use it in GitHub Desktop.
// a code snippets from underscore.js for type checking in JavaScript
_.each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp', 'Error'], function(name) {
_['is' + name] = function(obj) {
return toString.call(obj) === '[object ' + name + ']';
};
});
function isObject(item) {
const type = typeof item
// careful that typeof null === 'object'
return type === 'object' && !!item || type === 'function'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment