JavaScript inheritance Object.create() not working as expected

后端 未结 3 363
刺人心
刺人心 2021-01-21 18:45

I have:

Master object

function Fruit() {
    this.type = \"fruit\";
}

Sub-object:

function Bannana() {
    this.color =         


        
3条回答
  •  余生分开走
    2021-01-21 19:36

    You never put anything on the Fruit prototype object. Your constructor initializes the instances, not the prototype.

    If you had:

    Fruit.prototype.type = "fruit";
    

    then your code would work as you expect.

提交回复
热议问题