Last active
October 29, 2017 01:30
-
-
Save cyan33/3b6c27490b5db4296d82b451c9fa38c6 to your computer and use it in GitHub Desktop.
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
// 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