在 UnderscoreJS 的引擎盖下,我看到:
_.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]';
};
这似乎是一个奇怪的选择。为什么不直接使用 typeof 来确定一个值是字符串、函数还是数字?使用 toString 是否有性能提升?旧浏览器不支持 typeof 吗?