What are the advantages that prototype based OO has over class based OO?

前端 未结 7 1483
借酒劲吻你
借酒劲吻你 2020-11-30 23:18

Why is class based OO so popular instead of prototype based OO? Do they teach the latter in schools? Though Javascript is prototype based, most people use it mostly function

7条回答
  •  情书的邮戳
    2020-12-01 00:06

    If you're looking for someone to point out the advantages/disadvantages of each as an explanation for their popularity, I think you're falling for a fallacy which is for some reason very common in technology - that popularity has something to do with some absolute measure of quality.

    The truth is a lot more bland - class based OO is popular because Java uses classic OO, and Sun spent millions of dollars and a very long time building the popularity of Java - making sure people know it's used successfully in corporations, taught widely in universities, and on high school AP tests.

    Prototypal/classical OO are just different ways of organizing your ideas. You can implement either one in languages that don't support it natively (Python and Java come to mind, and JavaScript on the other side).

    In classical OO, you define an abstract hierarchy of classes for your objects, and then actually work with instances of those classes. In prototypal inheritance, you create a hierarchy of object instances. Although I imagine it might be a bit heretical in both camps, I don't see a reason you couldn't mix the two...

提交回复
热议问题