Javascript Object.isPrototypeOf ()

JavaScript Object.isPrototypeOf () yöntemi, bir nesnenin başka bir nesnenin prototip zincirinde bulunup bulunmadığını kontrol eder.

isPrototypeOf()Yöntemin sözdizimi şöyledir:

 prototypeObj.isPrototypeOf(object)

İşte prototypeObjbir nesne.

isPrototypeOf () Parametreleri

isPrototypeOf()Yöntem alır:

  • nesne - Prototip zinciri aranacak nesne.

İsPrototypeOf () 'dan dönen değer

  • BooleanÇağıran nesnenin belirtilen nesnenin prototip zincirinde yer alıp almadığını gösteren bir döndürür .

Not: prototip zincirini kontrol etmediğinden operatörden isPrototypeOf()farklıdır .instanceofobjectprototypeObjprototypeObj.prototype

Örnek: Object.isPrototypeOf () kullanma

 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

Çıktı

 doğru doğru doğru doğru

Önerilen Kaynaklar: Javascript Object setPrototypeOf ()

Ilginç makaleler...