Created
November 3, 2020 13:05
-
-
Save brandonpapworth/8448b80bc3226c7db69db4bc12564756 to your computer and use it in GitHub Desktop.
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
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