News for hackers. Stuff that matters.
Re:Type Checking in JavaScript by ceautery on Wednesday November 06, 2013 @10:26AM (#6683140)
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.

There are no comments on this comment yet.