javascript 判断对象是否为空
function is_empty(obj) {
"use strict";
if (Object.prototype.toString.call(obj) === '[object Object]') {
// Assume if it has a length property with a non-zero value
// that that property is correct.
if (obj.length && obj.length > 0){ return false; }
if (obj.length && obj.length === 0){return true; }
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) { return false; }
}
} else if (Object.prototype.toString.call(obj) === '[object Array]') {
if (obj.length && obj.length > 0){ return false; }
}
return true;
}
