类在基于原型继承的语言中的使用 [英] class use in a prototypal inheritance-based language

查看:70
本文介绍了类在基于原型继承的语言中的使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在回答此问题后很好地解释了经典继承原型继承之间的差异。这是我感兴趣的,因为我开始使用Java,但转移到Javascript。

The following answer to this question does a great job explaining the differences between classical inheritance and prototypal inheritance. this was of interest to me to understand because I started working in Java, but moved over to Javascript.

在他的回答中,他陈述原型继承,所有关于课程的业务都消失了。如果你想要一个物体,你只需要写一个物体。

In his answer, he states for prototypal inheritance that, "All of the business about classes goes away. If you want an object, you just write an object."

然而,有太多的文件和问题如何在Javascript中编写类。

Yet there is so much documentation and questions on how to "write classes" in Javascript.

为什么要推动使用这种语言呢?不是。我正在寻找具体的例子,在这种原型语言中使用JS应用程序中的类更为明智,以及将方形钉固定在圆孔中的好处。正如Aravind所说的那样,为什么人们通过将Javascript与其他人进行比较来学习Javascript,而不是因为它的目的......为什么这种做法似乎受到鼓励?

Why is there push to make the language something it is not. I'm looking for concrete examples of cases where using classes in JS applications are more sensible in this prototypal language and the benefits of awkwardly fitting a square peg into a round hole. As Aravind put it, why are people learning Javascript by comparing it to others, and not as it was intended... and why is this practice seemingly encouraged?

底线问题:为什么要在ECMAScript 6中引入类?

Bottomline question: Why are classes being introduced in ECMAScript 6?

推荐答案

群众喜欢上课。

没有什么更多或者对于原型遗传不太自然,这完全是主观的。 JS就是它自己的语言,就像Smalltalk和Self对于它作为一个对象意味着什么有不同的看法。

There's nothing "more" or "less" natural about prototypal inheritance, this is entirely subjective. JS is its own language, just like Smalltalk and Self had different ideas about what it meant to be an object.

ES6课程是语法糖。它们规范化/清理JS中如何使用继承/等。

ES6 classes are syntactic sugar. They normalize/clean up how inheritance/etc are to be used in JS.

与CoffeeScript类似,他们试图标准化如何在JS中完成OOP,并使那些不习惯原型继承的人更熟悉。

Similar to CoffeeScript, they attempt to standardize how OOP is done in JS, and make it more familiar to people that aren't used to prototypal inheritance.

这篇关于类在基于原型继承的语言中的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆