日期:2014-05-16  浏览次数:20337 次

How to check if object has any properties in JavaScript?
http://stackoverflow.com/questions/2673121/how-to-check-if-object-has-any-properties-in-javascript


function isEmptyObject(obj) {
  for(var prop in obj) {
    if (Object.prototype.hasOwnProperty.call(obj, prop)) {
      return false;
    }
  }
  return true;
}

isEmptyObject({}); // true
isEmptyObject({foo:'bar'});  // false