frontend-challenges
frontend-challenges copied to clipboard
32 - InstanceOfClass
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)
}
}