possibly a direct instance of a class
a class constructor (usually starts with big letter!)
class Animal {}
class Dog extends Animal {}
const dog = new Dog()
isOwnInstance(dog, Dog) => true
isOwnInstance(dog, Animal) => false // dog's direct prototype is Dog.prototype
isInstance(dog, Animal) => true // for comparison: instanceof walks the chain
isOwnInstance({}, Object) => true
isOwnInstance([], Object) => false // direct prototype is Array.prototype
isOwnInstance([], Array) => true
isOwnInstance(/hello/i, RegExp) => true
isOwnInstance('plain str', String) => false
isOwnInstance(22, Number) => false
isOwnInstance(Object.create(null), Object) => false
Checks if a value was directly constructed by the provided class (ignores inheritance)
Unlike isInstance which uses
instanceofand walks the prototype chain,isOwnInstanceonly returnstruewhen the value's immediate prototype matchesclassConstructor.prototype. This means subclass instances returnfalsewhen checked against a parent class.