Called on an object instance, accepts an object as argument. If the object you called isPrototypeOf()
on appears in the prototype chain of the object passed as argument, it returns true
. Otherwise it returns false
.
在对象实例上调用,接受一个对象作为参数。 如果调用isPrototypeOf()
的对象出现在作为参数传递的对象的原型链中,则返回true
。 否则返回false
。
Example:
例:
const Animal = {
isAnimal: true
}
const Mammal = Object.create(Animal)
Mammal.isMammal = true
Animal.isPrototypeOf(Mammal) //true
const dog = Object.create(Animal)
Object.setPrototypeOf(dog, Mammal)
Animal.isPrototypeOf(dog) //true
Mammal.isPrototypeOf(dog) //true
翻译自: https://flaviocopes.com/javascript-object-prototype-isprototypeof/