JS判断对象是否位空

来源:互联网 发布:淘宝首页怎么添加视频 编辑:程序博客网 时间:2024/06/08 08:40
function isEmpty(obj) {    // null and undefined are "empty"    if (obj == null) return true;    // Assume if it has a length property with a non-zero value    // that that property is correct.    if (obj.length > 0)    return false;    if (obj.length === 0)  return true;    // Otherwise, does it have any properties of its own?    // Note that this doesn't handle    // toString and toValue enumeration bugs in IE < 9    for (var key in obj) {        if (hasOwnProperty.call(obj, key)) return false;    }    return true;}

0 0
原创粉丝点击