# 如何实现一个函数 isPlainObject 判断是否为纯对象

Issue

欢迎在 Issue 中交流与讨论: Issue 409 (opens new window)

function isPlainObject(obj: any): boolean {
  if (typeof obj !== 'object' || obj === null) return false

  let proto = obj
  while (Object.getPrototypeOf(proto) !== null) {
    proto = Object.getPrototypeOf(proto)
  }

  return Object.getPrototypeOf(obj) === proto                                                  } 
}
Last Updated: 1/17/2021, 2:02:56 PM