Looking under the hood in UnderscoreJS, I see:
_.isFunction = function(obj) {
return toString.call(obj) == '[object Function]';
};
_.isString = function(obj) {
return toString.call(obj) == '[object String]';
};
_.isNumber = function(obj) {
return toString.call(obj) == '[object Number]';
};
This seems like an odd choice. Why not just use typeof to determine whether a value is a string, function, or number? Is there a performance gain by using toString? Is typeof not supported by older browsers?
typeof
has existed in every version of JavaScript since version 1.1 in 1996. – Tim Down May 1 '12 at 8:22