本文介绍了JavaScript ECMAScript 5中的类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道JavaScript ECMAScript 5中是否有类?我读了一些文献,对此有不同的看法。我知道可以模拟类,但是我不确定它们是否称为类。

I would like to get to know if there are classes in JavaScript ECMAScript 5? I read some literature and there are different opinions about it. I know that it is possible to emulate classes, but I am not sure if they are called classes. Do you maybe also have some proofs?

这些类仅仅是伪类还是正确的用语?

Are these classes simply pseudo classes or what is the correct term for it?

推荐答案

JavaScript / ECMAScript是基于原型的

JavaScript/ECMAScript is a prototype-based programming language.

维基百科对此的定义是:

Wikipedia’s definition of this is:

好吧,知道它是您的决定是否称其为 classes

Well, know it is your decision whether to call them classes.

但是JS世界中的某些人称它们为类,而使用ECMAScript 6时,会有一个关键字来创建此类原型,称为 class 。 (这暗示这些原型应称为 class 。)

But some people in the JS world call them classes and with ECMAScript 6 there will be a keyword to create such prototypes, called class. (Which implies that these prototypes should be called class.)

由于您正在编写在论文中,您可以定义类的定义(那里有一些定义),提及您使用的类以及它是否适用于JavaScript。 (如果某种程度上属于您的工作。)

Since you are writing a paper, you could take a definition of class (there are a few out there), mention which you used and whether that is applicable in JavaScript. (If that somehow belongs to your work.)

class 的一些定义在John C. Mitchell的一本很棒的书中也得到了总结。 (Mitchell,John:《编程语言的概念》,剑桥大学出版社,2003年。)

Some definitions of class are also summarized in a great book by John C. Mitchell. (Mitchell, John: Concepts in Programming Languages. Cambridge University Press, 2003.)

在Simula中的 classes 上,他写道:(p。326

On classes in Simula he writes: (p. 326)

在Smalltalk的 classes 中,他写道:(第327页)。

On classes in Smalltalk he writes: (p. 327)

他还指出Java和C ++中的 classes 概念与面向对象服务的先驱Smalltalk中的概念非常相似。

He also states that the concept of classes in Java and C++ is very similar to the concept in Smalltalk, which was a OO pioneer.

我们可以看到 class 的定义可以不同,但​​是上述两个定义似乎与JavaScript原型不太匹配。

We can see that class can be defined differently, but both definitions above don’t seem to quite match JavaScript prototypes.

这篇关于JavaScript ECMAScript 5中的类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!