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.
Hm, not sure what's your point. $.type purpose is something like
typeof
, but obviously it is not the same. There is many cases wheretypeof
is not only inconsistent between browsers, but also strange in spec too ("function" only because callable). Alsotypeof new String("foo") === "object"
is not what you wont in majority of cases.So, yes, you can see $.type something like
typeof
but more useful.