JavaScript ECMAScript 5中的类? [英] Classes in JavaScript ECMAScript 5?

查看:84
本文介绍了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:


Prototype-基于程序的编程是一种面向对象的编程,其中行为重用(称为继承)是通过克隆用作原型的现有对象的过程来执行的。这种模型也可以称为原型,面向原型,无类或基于实例的编程。

Prototype-based programming is a style of object-oriented programming in which behaviour reuse (known as inheritance) is performed via a process of cloning existing objects that serve as prototypes. This model can also be known as prototypal, prototype-oriented, classless, or instance-based programming.

好吧,知道它是您的决定是否称其为 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)


Class:Simula类是一个返回指向其激活记录的指针的过程。类的主体可以初始化其创建的对象。

Class: A Simula class is a procedure that returns a pointer to its activation record. The body of a class may initialize the object it creates.

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

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


Class:Smalltalk类定义了类变量,类方法以及实例方法,这些变量由类的所有对象共享类。在运行时,类数据结构包含指向实例变量Temple,方法字典和超类的指针。

Class: A Smalltalk class defines class variables, class methods, and the instance methods that are shared by all objects of the class. At run time, the class data structure contains pointers to an instance variable temple, a method dictionary, and the superclass.

他还指出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中的类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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