diff --git a/test/functions.js b/test/functions.js index 96292b563..b976977e7 100644 --- a/test/functions.js +++ b/test/functions.js @@ -76,7 +76,7 @@ $(document).ready(function() { setTimeout(throttledIncr, 70); setTimeout(throttledIncr, 110); setTimeout(throttledIncr, 120); - _.delay(function(){ ok(counter == 3, "incr was throttled"); start(); }, 180); + _.delay(function(){ ok(counter == 3, "incr was throttled"); start(); }, 200); }); asyncTest("functions: debounce", 1, function() { diff --git a/test/objects.js b/test/objects.js index 04577994a..b47de7fc4 100644 --- a/test/objects.js +++ b/test/objects.js @@ -86,7 +86,7 @@ $(document).ready(function() { parent.iRegExp = /hi/;\ parent.iNaN = NaN;\ parent.iNull = null;\ - parent.iBoolean = false;\ + parent.iBoolean = false;\ parent.iUndefined = undefined;\ " ); @@ -125,7 +125,7 @@ $(document).ready(function() { ok(!_.isNumber(arguments), 'the arguments object is not a number'); ok(!_.isNumber(undefined), 'undefined is not a number'); ok(_.isNumber(3 * 4 - 7 / 10), 'but numbers are'); - ok(_.isNumber(NaN), 'NaN is a number'); + ok(!_.isNumber(NaN), 'NaN is not a number'); ok(_.isNumber(Infinity), 'Infinity is a number'); ok(_.isNumber(iNumber), 'even from another frame'); }); @@ -183,11 +183,24 @@ $(document).ready(function() { ok(!_.isUndefined(1), 'numbers are defined'); ok(!_.isUndefined(null), 'null is defined'); ok(!_.isUndefined(false), 'false is defined'); + ok(!_.isUndefined(NaN), 'NaN is defined'); ok(_.isUndefined(), 'nothing is undefined'); ok(_.isUndefined(undefined), 'undefined is undefined'); ok(_.isUndefined(iUndefined), 'even from another frame'); }); + if (window.ActiveXObject) { + test("objects: IE host objects", function() { + var xml = new ActiveXObject("Msxml2.DOMDocument.3.0"); + ok(!_.isNumber(xml)); + ok(!_.isBoolean(xml)); + ok(!_.isNaN(xml)); + ok(!_.isFunction(xml)); + ok(!_.isNull(xml)); + ok(!_.isUndefined(xml)); + }); + } + test("objects: tap", function() { var intercepted = null; var interceptor = function(obj) { intercepted = obj; }; diff --git a/underscore.js b/underscore.js index 33925ded8..291b97617 100644 --- a/underscore.js +++ b/underscore.js @@ -588,7 +588,13 @@ // Is a given value a number? _.isNumber = function(obj) { - return (obj === +obj) || (toString.call(obj) === '[object Number]'); + return !!(obj === 0 || (obj && obj.toExponential && obj.toFixed)); + }; + + // Is the given value NaN -- this one is interesting. NaN != NaN, and + // isNaN(undefined) == true, so we make sure it's a number first. + _.isNaN = function(obj) { + return toString.call(obj) === '[object Number]' && isNaN(obj); }; // Is a given value a boolean? @@ -606,12 +612,6 @@ return !!(obj && obj.test && obj.exec && (obj.ignoreCase || obj.ignoreCase === false)); }; - // Is the given value NaN -- this one is interesting. NaN != NaN, and - // isNaN(undefined) == true, so we make sure it's a number first. - _.isNaN = function(obj) { - return _.isNumber(obj) && isNaN(obj); - }; - // Is a given value equal to null? _.isNull = function(obj) { return obj === null; @@ -619,7 +619,7 @@ // Is a given variable undefined? _.isUndefined = function(obj) { - return typeof obj == 'undefined'; + return obj === void 0; }; // Utility Functions