In underscore.js, the following code seems to add _.isNumber()
// Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp.
each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], function(name) {
_['is' + name] = function(obj) {
return toString.call(obj) == '[object ' + name + ']';
};
});
but there must be something else going on, because copying this code straight into firefox causes it to fail as toString.call(5) returns [xpconnect wrapped native prototype] — so its obviously doing something else somewhere – but I can’t figure out what.
Here’s an example of the results in firefox:
Your jsbin is showing
window.toString, where as underscore is usingObject.prototype.toString, they have aliased it totoStringlocally in their code.See http://jsbin.com/uviyaz/3/edit
See also underscore’s source where they do it: