常规数据类型检测方法

  1. 在coding中,我们经常要判断参数的类型。以下整理常用的数据类型的检测的方法。

/*

* @intention 数字

*/

function isNumber(s) {

return ! isNaN(s);

}

/*

* @intention 字符串

*/

function isString(s) {

return typeof s === ''string";

}

/*

* @intention 布尔

*/

function isBoolean(s) {

return typeof s === ''Boolean";

}

/*

* @intention 函数

*/

function isFunction(s) {

return typeof s === "function";

}

/*

* @intention null

*/

function isNull(s) {

return s === null; // 若使用“==” null 和 undefined 均返回true

}

/*

* @intention undefined

*/

function isUndefined(s) {

return typeof s === "undefined";

}

/*

* @intention 空

*/

function isEmpty(s) {

return /^\s*$/.test(s);

}

/*

* @intention 数组

*/

function isArray(s) {

return s instanceof Array;

}

/*

* @intention 日期

*/

function isDate(s) {

return d instanceof Date;

}

/*

* @intention 是否为空的对象

*/

function isEmptyObj(obj) {

var cnt = 0, objBln = true;

for(var i in obj) {

i ? cnt++ :‘’;

}

if (cnt > 0)

objBln = false;

return objBln;

}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值