常用判断方法

1.

function isUndefinedOrNull(obj){
    return typeof obj === 'undefined' || obj === null;
}
function isNullOrWhiteSpace(obj){
    return typeof str === 'undefined' || str === null || /^\s*$/.test(str);
}
function isBoolean(obj){
    return obj === true || obj === false;
}
function isInt(obj){
    return Number(obj) === obj && obj % 1 === 0;
}
function isFloat(obj){
    return obj === Number(obj) && obj % 1 !== 0;
}
function isNumber(obj){
    return obj === Number(obj);
}
function padLeft(obj){
    return (Array(length).join('0') + n).substr(-length);
}
function objectLength(obj){
    var size = 0, key;
    for (key in obj) {
        if (obj.hasOwnProperty(key)) size++;
    }
    return size;
}
function IsNullOrEmpty(obj){
    str === null || str==="";
}

猜你喜欢

转载自www.cnblogs.com/YCiCi/p/12560625.html