ut2
Version:
一个现代 JavaScript 实用工具库。[点击查看在线文档]。
21 lines (17 loc) • 727 B
JavaScript
;
var getTag = require('./internals/getTag.js');
var native = require('./internals/native.js');
var isObjectLike = require('./isObjectLike.js');
var objectCtorString = native.functionProtoToString.call(Object);
function isPlainObject(value) {
if (!isObjectLike(value) || getTag(value) !== native.objectTag) {
return false;
}
var proto = native.objectGetPrototypeOf(Object(value));
if (proto === null) {
return true;
}
var Ctor = native.objectProtoHasOwnProperty.call(proto, 'constructor') && proto.constructor;
return typeof Ctor === 'function' && Ctor instanceof Ctor && native.functionProtoToString.call(Ctor) === objectCtorString;
}
module.exports = isPlainObject;