Skip to content

Instantly share code, notes, and snippets.

@liuwenzhuang
Last active February 25, 2018 05:50
Show Gist options
  • Save liuwenzhuang/a42c865cb0c01ce20f599190179522ba to your computer and use it in GitHub Desktop.
Save liuwenzhuang/a42c865cb0c01ce20f599190179522ba to your computer and use it in GitHub Desktop.
判断是否为Plain Object(Plain Object意为用JSON形式定义的普通对象或者new Object()创建的简单对象)
/**
* @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