Why was JavaScript implemented using prototypal inheritance?

前端 未结 6 759
青春惊慌失措
青春惊慌失措 2021-02-05 15:44

There are lots of articles and posts explaining how JavaScript inheritance works, but why was JavaScript implemented using prototypal inheritance instead of classical inheritanc

6条回答
  •  庸人自扰
    2021-02-05 15:57

    I think it was chosen because it is easy to implement, needs no extra keywords and users don't need to understand it to be able to use the language. It is also more powerfull and flexible than class based inheritance.

    It's a natural choice for a untyped language. The main advantages of class based inheritance are that it allows static typing and thus type checking and a faster table based lookup implementation.

提交回复
热议问题