isPlainObject() function
检查 value 是否为纯对象(plain object),即原型为 Object.prototype 的对象(如对象字面量、new Object())或原型为 null 的对象(Object.create(null))。
与 isObject 不同(isObject 对包括数组和函数在内的所有非原始值返回 true),isPlainObject 对数组、函数、类实例以及 Date、Map、Set 等内置对象返回 false。
Signature:
typescript
isPlainObject: (value: unknown) => value is Record<PropertyKey, unknown>Example
ts
isPlainObject({}); // true
isPlainObject({ a: 1 }); // true
isPlainObject(Object.create(null)); // true
isPlainObject([1, 2, 3]); // false
isPlainObject(() => {}); // false
isPlainObject(new Date()); // false
isPlainObject(null); // false
isPlainObject(123); // false