type.js - offers an more consistent type checking of native values.
It relays on the [[Class]] of objects instead on typeof
results.
type2.js - variation that returns "object" for wrapped natives. This one is probably more noob-immune, avoiding some possible strange situations.
Consider something like this:
// Defined by third...
var foo = new String("foo");
// ...
function noob( str ) {
if ( type(str) !== "string" ) {
throw new TypeError("string expected");
}
return ( str === "foo" );
}
If the type check returns "string"
, then noob
will return false
because of the strict equality check ===
. To avoid similar situations, "object" is returned for wrapped strings, numbers and booleans.
There are inconsistencies even between specs (that is reasonable), I know.