
Untitled
By: a guest on
May 17th, 2012 | syntax:
None | size: 0.57 KB | hits: 13 | expires: Never
var o = {};
function getIsType(type) {
return function (o) {
return /* undefined */ typeof o === type ||
/* null */ o === null && type === "null" ||
Object.prototype.toString.call(o).match(/\s+(\w+)/)[1].toLowerCase() === type;
};
}
var types = "String Number Date Object Array RegExp Function Null Undefined Boolean".split(" ");
for (var i in types) {
if (types.hasOwnProperty(i)) {
o["is" + types[i]] = getIsType(types[i].toLowerCase());
}
}
// o.isString("") === true
// o.isNull(null) === true
// o.isUndefined() === true