Prototypal inheritance in JavaScript

后端 未结 4 1991
不知归路
不知归路 2021-02-03 13:31

I\'ve been watching Douglas Crockford\'s talks at YUI Theater, and I have a question about JavaScript inheritance...

Douglas gives this example to show that \"Hoozit\" i

4条回答
  •  眼角桃花
    2021-02-03 13:55

    The reason is that using Hoozit.prototype = Gizmo.prototype would mean that modifying Hoozit's prototype object would also modify objects of type Gizmo, which is not expected behavior.

    Hoozit.prototype = new Gizmo() inherits from Gizmo, and then leaves Gizmo alone.

提交回复
热议问题