frontend-challenges icon indicating copy to clipboard operation
frontend-challenges copied to clipboard

32 - InstanceOfClass

Open jsartisan opened this issue 1 year ago • 0 comments

index.js

export function instanceOfClass(obj, targetClass) {
  if (!obj || typeof obj !== 'object') return false
  if (!targetClass.prototype) throw Error

  if (Object.getPrototypeOf(obj) === targetClass.prototype) {
    return true
  } else {
    return instanceOfClass(Object.getPrototypeOf(obj), targetClass)
  }
}

jsartisan avatar Mar 13 '24 03:03 jsartisan