JSFiddle - React, Tailwind, and code Playground
JavaScript
hasProto = {}.__proto__ == Object.prototype
window.isPlainObject = hasProto ? function (obj) {
return obj && typeof obj === "object" && obj.__proto__ === Object.prototype;
} : function (obj) {
return obj && typeof obj === "object" && Object.getPrototypeOf(obj) === Object.prototype;
};
document.writeln("Expected:", true, ", actual: ", isPlainObject({}), "<br/>");
document.writeln("Expected:", true, ", actual: ", isPlainObject({a:1}), "<br/>");
document.writeln("Expected:", true, ", actual: ", isPlainObject(new Object), "<br/>");
function ctor() {}
document.writeln("Expected:", false, ", actual: ", isPlainObject(new ctor), "<br/>");
document.writeln("Expected:", false, ", actual: ", isPlainObject(ctor), "<br/>");
document.writeln("Expected:", false, ", actual: ", isPlainObject("a"), "<br/>");
document.writeln("Expected:", false, ", actual: ", isPlainObject(new String("a")), "<br/>");
document.writeln("Expected:", false, ", actual: ", isPlainObject(true), "<br/>");
document.writeln("Expected:", false, ", actual: ", isPlainObject(12), "<br/>");
document.writeln("Expected:", false, ", actual: ", isPlainObject(/abc/i), "<br/>");