Metoda JavaScript Object.isPrototypeOf () kontroluje, zda objekt existuje v řetězci prototypu jiného objektu.
Syntaxe isPrototypeOf()metody je:
prototypeObj.isPrototypeOf(object)
Tady prototypeObjje objekt.
isPrototypeOf () parametry
isPrototypeOf()Metoda bere v:
- objekt - Objekt, jehož prototypový řetězec bude prohledán.
Vrátit hodnotu z isPrototypeOf ()
- Vrátí
Booleanindikaci, zda volající objekt leží v řetězci prototypu zadaného objektu.
Poznámka: isPrototypeOf() liší se od instanceofoperátora tím, že kontroluje objectprototypový řetěz proti prototypeObjne prototypeObj.prototype.
Příklad: Použití Object.isPrototypeOf ()
let obj = new Object(); console.log(Object.prototype.isPrototypeOf(obj)); // true console.log(Function.prototype.isPrototypeOf(obj.toString)); // true console.log(Array.prototype.isPrototypeOf((2, 4, 8))); // true // define object let Animal = ( makeSound() ( console.log(`$(this.name), $(this.sound)!`); ), ); // new object function Dog(name) ( this.name = name; this.sound = "bark"; // setting prototype using setPrototypeOf() Object.setPrototypeOf(this, Animal); ) dog1 = new Dog("Marcus"); console.log(Animal.isPrototypeOf(dog1)); // true
Výstup
true true true true
Doporučené čtení: Javascript Object setPrototypeOf ()








