Skip to content

Commit 813a80c

Browse files
committed
ref: Update IsPlainObject
Update isPlainObject in order to increase speed and better understanding.
1 parent 792d0b4 commit 813a80c

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/utils/isPlainObject.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
* @returns True if the argument appears to be a plain object.
44
*/
55
export default function isPlainObject(obj: any): boolean {
6-
if (typeof obj !== 'object' || obj === null) return false
6+
if (!obj) return false
77

8-
let proto = obj
9-
while (Object.getPrototypeOf(proto) !== null) {
10-
proto = Object.getPrototypeOf(proto)
11-
}
8+
const proto = Object.getPrototypeOf(obj)
129

13-
return Object.getPrototypeOf(obj) === proto
10+
return (
11+
proto === null ||
12+
(Object.getPrototypeOf(proto) === null &&
13+
proto.constructor === obj.constructor)
14+
)
1415
}

0 commit comments

Comments
 (0)