Why was JavaScript implemented using prototypal inheritance?

前端 未结 6 755
青春惊慌失措
青春惊慌失措 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 16:08

    Unless one of the designers of JavaScript stops by to weigh in, we can only speculate. That having been said, here's my take:

    JavaScript is executed as it is interpreted, so there is no concept of separating the declaration of an object's type from the object itself. It's a very functional approach. The instance is coming into existence as it is being described - we are always operating on active instances. Because of this, the concept of a class - or a passive "instance template" - has no real place.

提交回复
热议问题