一.判断是否为数组类型
var a=[0];
document.write(isArray(a),'<br/>');
function isArray(obj){
return (typeof obj=='object')&&obj.constructor==Array;
}
二.判断是否为字符串类型
document.write(isString('test'),'<br/>');
document.write(isString(10),'<br/>');
function isString(str){
return (typeof str=='string')&&str.constructor==String;
}
三.判断是否为数值类型
document.write(isNumber('test'),'<br/>');
document.write(isNumber(10),'<br/>');
function isNumber(obj){
return (typeof obj=='number')&&obj.constructor==Number;
}
四.判断是否为日期类型
document.write(isDate(10),'<br/>');
function isDate(obj){
return (typeof obj=='object')&&obj.constructor==Date;
}
五.判断是否为函数
document.write(isFunction(10),'<br/>');
function isFunction(obj){
return (typeof obj=='function')&&obj.constructor==Function;
}
六.判断是否为对象
document.write(isObject(new Object()),'<br/>');
document.write(isObject(10),'<br/>');
function isObject(obj){
return (typeof obj=='object')&&obj.constructor==Object;
}
原文地址