Reputation:
Per Crockford's, The Good Parts
typeof is accurate for function, string, number, boolean, and undefined. null and array are both incorrectly reported as object.
So why not use typeof for the cases in which it does work? It is always faster that is why I wonder why it is not preferred in these cases.
Particularly here for function, string and number.
http://underscorejs.org/docs/underscore.html#section-111
each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], function(name) {
_['is' + name] = function(obj) {
return toString.call(obj) == '[object ' + name + ']';
}; });
Upvotes: 0
Views: 150
Reputation: 887415
The point of these wrappers is to catch boxed value objects.
typeof new Number(1) === 'object'
Upvotes: 2