use more robust type checks
This commit is contained in:
parent
80a11082b1
commit
a7963dc9a4
1 changed files with 8 additions and 19 deletions
|
|
@ -140,25 +140,27 @@ exports.rateLimit = function(maxRate, scope, func) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var objectToString = Object.prototype.toString;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true if it is a String
|
* Return true if it is a String
|
||||||
*/
|
*/
|
||||||
exports.isString = function(it) {
|
exports.isString = function(it) {
|
||||||
return (typeof it == "string" || it instanceof String);
|
return it && objectToString.call(it) === "[object String]";
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if it is a Boolean.
|
* Returns true if it is a Boolean.
|
||||||
*/
|
*/
|
||||||
exports.isBoolean = function(it) {
|
exports.isBoolean = function(it) {
|
||||||
return (typeof it == 'boolean');
|
return it && objectToString.call(it) === "[object Boolean]";
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if it is a Number.
|
* Returns true if it is a Number.
|
||||||
*/
|
*/
|
||||||
exports.isNumber = function(it) {
|
exports.isNumber = function(it) {
|
||||||
return (typeof it == 'number' && isFinite(it));
|
return it && objectToString.call(it) === "[object Number]" && isFinite(it);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -174,22 +176,9 @@ exports.isObject = function(it) {
|
||||||
* Is the passed object a function?
|
* Is the passed object a function?
|
||||||
* From dojo.isFunction()
|
* From dojo.isFunction()
|
||||||
*/
|
*/
|
||||||
exports.isFunction = (function() {
|
exports.isFunction = function(it) {
|
||||||
var _isFunction = function(it) {
|
return it && objectToString.call(it) === "[object Function]";
|
||||||
var t = typeof it; // must evaluate separately due to bizarre Opera bug. See #8937
|
};
|
||||||
//Firefox thinks object HTML element is a function, so test for nodeType.
|
|
||||||
return it && (t == "function" || it instanceof Function) && !it.nodeType; // Boolean
|
|
||||||
};
|
|
||||||
|
|
||||||
return exports.isSafari ?
|
|
||||||
// only slow this down w/ gratuitious casting in Safari (not WebKit)
|
|
||||||
function(/*anything*/ it) {
|
|
||||||
if (typeof it == "function" && it == "[object NodeList]") {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return _isFunction(it); // Boolean
|
|
||||||
} : _isFunction;
|
|
||||||
})();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A la Prototype endsWith(). Takes a regex excluding the '$' end marker
|
* A la Prototype endsWith(). Takes a regex excluding the '$' end marker
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue