Created
July 1, 2017 09:40
-
-
Save ShenTengTu/97b666fd43185515f03fe841fda9f6dc to your computer and use it in GitHub Desktop.
Pure Object validation
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
/*isPureObject(item,strict) | |
- item(any) : the target to be checked. | |
- strict(boolean) : if 'true', just original Object can pass the check. | |
*/ | |
function isPureObject(item, strict) { | |
if (item !== null) { | |
if (typeof item === 'object' && !Array.isArray(item)) { | |
if (strict) { | |
if (item.__proto__.__proto__ === null) { | |
return true; | |
} else { | |
return false; | |
} | |
} else { | |
return true; | |
} | |
} else { | |
return false; | |
} | |
} else { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
see testing in JSFiddle :
https://jsfiddle.net/ShenTengTu/rghsnkct/