3 ms·
A simple "constructor.name" query covers most of this. You still need edge case checkers for null, Nan, and Infinity, but... function type(a) { var t = a
by ceautery 13y ago
A simple "constructor.name" query covers most of this. You still need edge case checkers for null, Nan, and Infinity, but...
function type(a) {
var t = a.constructor.name.toLowerCase();
return t.match(/^html/i) ? 'element' : t
}
...handles the rest. Still, I liked this post quite a bit; it shows pretty clearly how odd type checking can be in a loosely typed language.