{"comment":{"created_at":"2011-10-19T17:18:16Z","body":"I edited the [jsperf test case](http://jsperf.com/underscore-js-istype-alternatives). The speed diffs aren't as dramatic in Chrome and I added jQuery as a sanity check. As for a false positive, I did a quick search of the [issues](https://github.com/documentcloud/underscore/issues) and came up with [this](https://github.com/documentcloud/underscore/issues/10). Here is a summary of [my comments](http://jsperf.com/underscore-js-istype-alternatives#comments) on the perf test.\r\n\r\n## JSPerf Comments\r\n\r\n\r\n### Comment 1\r\nI doubt the speed diff will matter in real world use.\r\nI think using the internal `[[Class]]` is best because it's consistent with [ES5.1 spec](http://es5.github.com/#x15.4.3.2), `_.isArray()`, and with popular libs like jQuery which are often paired with underscore.js.\r\n\r\nI believe [@kitcambridge](http://twitter.com/kitcambridge) also mentioned that by using the internal `[[Class]]` underscore.js could simplify its `_.isEqual()` method too.\r\n\r\nAlso keep in mind there are differences in the results of these implementations. For example\r\n\r\n``` js\r\n_.isNumber(NaN); // false\r\n_.isNumberNew(NaN); // true\r\njQuery.type(NaN); // \"number\"\r\n```\r\n\r\nAs with any sugar if performance ever becomes an issue devs can drop back to de-sugared simple `typeof` checks where suitable. \r\n\r\n*Note: I tweaked the test to work in IE and added jQuery as a sanity check.*\r\n\r\n----\r\n\r\n### Comment 3\r\n\r\nThe concern over performance in these sugar methods is misplaced. It's better for these methods to follow spec precedents *(set by `Array.isArray`)* to avoid potential [false positives](https://github.com/documentcloud/underscore/issues/10) and create consistent behavior in the API *(aligning with `_.isArray`)*.\r\n\r\nAs for `_.isNumber`, I wasn't debating the merits of one implementation over the other. I was only giving a heads-up to their differences.\r\n\r\nThough by your preference Underscore.js *v1.2.0* is actually inconsistent with what it considers a number because it allows `_.isNumber(Infinity); // true`.\r\n\r\nYou can't go wrong following spec and checking the internal `[[Class]]`. If someone has a *WTF* moment with `NaN` or `Infinity` they can take that time to actually [read the spec](http://es5.github.com/#x8.5) and learn something about the language.\r\n\r\n``` js\r\nNaN.constructor == Number; // true\r\nInfinity.constructor == Number; // true\r\ntypeof NaN.toFixed // function\r\ntypeof Infinity.toPrecision // function\r\n\r\nvar n = Object(NaN);\r\nisNaN(n); // true\r\nn == n; // true\r\n\r\nNumber.prototype.toJSON = function() { return isFinite(this) ? this : String(this); };\r\nJSON.stringify(n); // '\"NaN\"'\r\n```\r\n\r\nThe concern over `NaN` and `Infinity` are edge cases and can be handled, when needed, with [`isFinite()`](http://es5.github.com/#x15.1.2.5).\r\n\r\n","updated_at":"2011-10-19T17:18:16Z","url":"https://api.github.com/repos/documentcloud/underscore/issues/comments/2458575","id":2458575,"user":{"avatar_url":"https://secure.gravatar.com/avatar/299a3d891ff1920b69c364d061007043?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"299a3d891ff1920b69c364d061007043","url":"https://api.github.com/users/jdalton","id":4303,"login":"jdalton"}},"action":"created","issue":{"number":321,"created_at":"2011-10-05T03:04:18Z","pull_request":{"diff_url":"https://github.com/documentcloud/underscore/pull/321.diff","patch_url":"https://github.com/documentcloud/underscore/pull/321.patch","html_url":"https://github.com/documentcloud/underscore/pull/321"},"body":"The current tests allow for too many false positives for my liking. This also changes `_.isNumber(NaN)` from `false` to `true`. It really should have been `true` in the first place.","comments":6,"title":"better isXXX checks","updated_at":"2011-10-19T17:18:16Z","url":"https://api.github.com/repos/documentcloud/underscore/issues/321","id":1820179,"assignee":null,"milestone":null,"closed_at":"2011-10-17T22:04:01Z","user":{"avatar_url":"https://secure.gravatar.com/avatar/24fb0088507077f7852adaec4f6b679f?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"24fb0088507077f7852adaec4f6b679f","url":"https://api.github.com/users/michaelficarra","id":218840,"login":"michaelficarra"},"html_url":"https://github.com/documentcloud/underscore/issues/321","labels":[{"name":"change","url":"https://api.github.com/repos/documentcloud/underscore/labels/change","color":"22694d"},{"name":"wontfix","url":"https://api.github.com/repos/documentcloud/underscore/labels/wontfix","color":"ffffff"}],"state":"closed"},"legacy":{"issue_id":1820179,"comment_id":2458575}}