Skip to content

Instantly share code, notes, and snippets.

@brandonpapworth
Created November 3, 2020 13:05
Show Gist options
  • Save brandonpapworth/8448b80bc3226c7db69db4bc12564756 to your computer and use it in GitHub Desktop.
Save brandonpapworth/8448b80bc3226c7db69db4bc12564756 to your computer and use it in GitHub Desktop.
var _toString = Object.prototype.toString;
var _getPrototypeOf = Object.getPrototypeOf;
function isPlainObject(value) {
switch(value) {
default:
if (_toString.call(value) === '[object Object]') {
break;
}
case null:
case undefined:
return false;
}
let valueProto = _getPrototypeOf(value);
let proto = valueProto;
let nextProto = valueProto;
while (true) {
if (nextProto === null) {
return valueProto === proto;
}
proto = nextProto;
nextProto = _getPrototypeOf(proto);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment