Overriding methods in Javascript

前端 未结 4 921
你的背包
你的背包 2020-12-10 03:52

I would like to know what is the difference between overriding methods with prototypes and without prototypes. Consider:

Example 1:

         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-10 04:19

    In the first method each of the Animal instance will get its own implementation of sleep and eat methods.

    While in the second model All instances will share the same instance of the sleep and eat methods.

    The second model is better since we can share the methods.

提交回复
热议问题