Skip to content

Instantly share code, notes, and snippets.

@fuchao2012
Created March 3, 2017 06:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fuchao2012/e8443e5608e8534a45fe7dd7dda4e8da to your computer and use it in GitHub Desktop.
Save fuchao2012/e8443e5608e8534a45fe7dd7dda4e8da to your computer and use it in GitHub Desktop.
isEmptyObject
// ES5-
if(!Object.prototype.isEmptyObject){
Object.prototype.isEmptyObject = function(value){
for (var key in value) {
if (hasOwnProperty.call(value, key)) {
return false;
}
}
return true;
}
}
//ES5+
if(!Object.prototype.isEmptyObject){
Object.prototype.isEmptyObject = ()=>{
return Object.keys(this).length === 0 && this.constructor === Object
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment