isPrototypeOf in Javascript

前端 未结 3 1158
星月不相逢
星月不相逢 2021-02-20 11:02

I am a beginner to JavaScript and on my way to Prototypes in JavaScript.
As per the article here

Creating

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-20 11:41

    I would agree that terminology is incorrect.

    The constructor function has a prototype property which defines the properties and methods in the prototype chain; but it is not itself the prototype of an object, it is the constructor.

    isPrototypeOf is not called on the constructor itself, but on the constructor's prototype property.

    alert(person.prototype.isPrototypeOf(myFather)); // true
    

    myFather would be an instanceof person, and you can test this using the following line.

    alert(myFather instanceof person); // true
    

提交回复
热议问题