Created
March 3, 2017 06:16
-
-
Save fuchao2012/e8443e5608e8534a45fe7dd7dda4e8da to your computer and use it in GitHub Desktop.
isEmptyObject
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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