js判断对象为空

http://www.jb51.net/article/42713.htm

var isEmptyValue = function(value) {
            var type;
            if(value == null) { // 等同于 value === undefined || value === null
                return true;
            }
            type = Object.prototype.toString.call(value).slice(8, -1);
            switch(type) {
            case 'String':
                return !$.trim(value);
            case 'Array':
                return !value.length;
            case 'Object':
                return $.isEmptyObject(value); // 普通对象使用 for...in 判断,有 key 即为 false
            default:
                return false; // 其他对象均视作非空
            }
        };

 

其中 isEmptyObject

function isEmptyObject(e) {  
    var t;  
    for (t in e)  
        return !1;  
    return !0  
}  

 

posted @ 2016-06-21 13:50  忘忧般若汤  阅读(3659)  评论(0编辑  收藏  举报