Last active
February 25, 2018 05:50
-
-
Save liuwenzhuang/a42c865cb0c01ce20f599190179522ba to your computer and use it in GitHub Desktop.
判断是否为Plain Object(Plain Object意为用JSON形式定义的普通对象或者new Object()创建的简单对象)
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
/** | |
* @param {any} obj The object to inspect. | |
* @returns {boolean} True if the argument appears to be a plain object. | |
*/ | |
function isPlainObject(obj) { | |
if (typeof obj !== 'object' || obj === null) return false; | |
let proto = obj; | |
while (Object.getPrototypeOf(proto) !== null) { | |
proto = Object.getPrototypeOf(proto); | |
} | |
return Object.getPrototypeOf(obj) === proto; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment