Skip to content

Instantly share code, notes, and snippets.

@hcl1687
hcl1687 / type.js
Last active April 19, 2017 03:32
type
const types = 'Boolean Number String Function Array Date RegExp Object Error'.split(' ')
const class2type = {}
types.forEach(name => {
class2type['[object ' + name + ']'] = name.toLowerCase()
})
function type (obj) {
if (obj === null) {
return obj + ''
}