mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 17:47:49 +00:00
Better Underscore isType checking, in the presence of Internet Explorer host objects, which are a bit touchy.
This commit is contained in:
@@ -76,7 +76,7 @@ $(document).ready(function() {
|
|||||||
setTimeout(throttledIncr, 70);
|
setTimeout(throttledIncr, 70);
|
||||||
setTimeout(throttledIncr, 110);
|
setTimeout(throttledIncr, 110);
|
||||||
setTimeout(throttledIncr, 120);
|
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() {
|
asyncTest("functions: debounce", 1, function() {
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ $(document).ready(function() {
|
|||||||
parent.iRegExp = /hi/;\
|
parent.iRegExp = /hi/;\
|
||||||
parent.iNaN = NaN;\
|
parent.iNaN = NaN;\
|
||||||
parent.iNull = null;\
|
parent.iNull = null;\
|
||||||
parent.iBoolean = false;\
|
parent.iBoolean = false;\
|
||||||
parent.iUndefined = undefined;\
|
parent.iUndefined = undefined;\
|
||||||
</script>"
|
</script>"
|
||||||
);
|
);
|
||||||
@@ -125,7 +125,7 @@ $(document).ready(function() {
|
|||||||
ok(!_.isNumber(arguments), 'the arguments object is not a number');
|
ok(!_.isNumber(arguments), 'the arguments object is not a number');
|
||||||
ok(!_.isNumber(undefined), 'undefined is not a number');
|
ok(!_.isNumber(undefined), 'undefined is not a number');
|
||||||
ok(_.isNumber(3 * 4 - 7 / 10), 'but numbers are');
|
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(Infinity), 'Infinity is a number');
|
||||||
ok(_.isNumber(iNumber), 'even from another frame');
|
ok(_.isNumber(iNumber), 'even from another frame');
|
||||||
});
|
});
|
||||||
@@ -183,11 +183,24 @@ $(document).ready(function() {
|
|||||||
ok(!_.isUndefined(1), 'numbers are defined');
|
ok(!_.isUndefined(1), 'numbers are defined');
|
||||||
ok(!_.isUndefined(null), 'null is defined');
|
ok(!_.isUndefined(null), 'null is defined');
|
||||||
ok(!_.isUndefined(false), 'false is defined');
|
ok(!_.isUndefined(false), 'false is defined');
|
||||||
|
ok(!_.isUndefined(NaN), 'NaN is defined');
|
||||||
ok(_.isUndefined(), 'nothing is undefined');
|
ok(_.isUndefined(), 'nothing is undefined');
|
||||||
ok(_.isUndefined(undefined), 'undefined is undefined');
|
ok(_.isUndefined(undefined), 'undefined is undefined');
|
||||||
ok(_.isUndefined(iUndefined), 'even from another frame');
|
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() {
|
test("objects: tap", function() {
|
||||||
var intercepted = null;
|
var intercepted = null;
|
||||||
var interceptor = function(obj) { intercepted = obj; };
|
var interceptor = function(obj) { intercepted = obj; };
|
||||||
|
|||||||
@@ -588,7 +588,13 @@
|
|||||||
|
|
||||||
// Is a given value a number?
|
// Is a given value a number?
|
||||||
_.isNumber = function(obj) {
|
_.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?
|
// Is a given value a boolean?
|
||||||
@@ -606,12 +612,6 @@
|
|||||||
return !!(obj && obj.test && obj.exec && (obj.ignoreCase || obj.ignoreCase === false));
|
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?
|
// Is a given value equal to null?
|
||||||
_.isNull = function(obj) {
|
_.isNull = function(obj) {
|
||||||
return obj === null;
|
return obj === null;
|
||||||
@@ -619,7 +619,7 @@
|
|||||||
|
|
||||||
// Is a given variable undefined?
|
// Is a given variable undefined?
|
||||||
_.isUndefined = function(obj) {
|
_.isUndefined = function(obj) {
|
||||||
return typeof obj == 'undefined';
|
return obj === void 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Utility Functions
|
// Utility Functions
|
||||||
|
|||||||
Reference in New Issue
Block a user