JavaScript和ECMAScript有什么区别?

by Michael Aranda

迈克尔·阿兰达(Michael Aranda)

JavaScript和ECMAScript有什么区别? (What’s the difference between JavaScript and ECMAScript?)

I’ve tried googling “the difference between JavaScript and ECMAScript.”

我尝试过搜索“ JavaScript和ECMAScript之间的区别”。

I ended up having to wade through a sea of ambiguous and seemingly conflicting results:

我最终不得不在模棱两可,看似矛盾的结果中徘徊:

“ECMAScript is a standard.”

“ ECMAScript是一个标准。”

“JavaScript is a standard.”

“ JavaScript是标准。”

“ECMAScript is a specification.”

“ ECMAScript是一个规范。”

“JavaScript is an implementation of the ECMAScript standard.”

“ JavaScript是ECMAScript标准的实现。”

“ECMAScript is standardized JavaScript.”

“ ECMAScript是标准化JavaScript。”

“ECMAScript is a language.”

“ ECMAScript是一种语言。”

“JavaScript is a dialect of ECMAScript.”

“ JavaScript是ECMAScript的方言。”

“ECMAScript is JavaScript.”

“ ECMAScript JavaScript。”

Holding back the urge to cry, I bucked up and decided to commit to some painful yet productive research.

我忍住了哭泣的冲动,坚持不懈,决定进行一些痛苦但富有成效的研究。

This article represents my current understanding of the differences between JavaScript and ECMAScript. It is geared towards people who are familiar with JavaScript but would like a clearer understanding of its relationship with ECMAScript, web browsers, Babel, and more. You will also learn about scripting languages, JavaScript engines, and JavaScript runtimes for good measure.

本文代表了我目前对JavaScript和ECMAScript之间差异的理解。 它适用于熟悉JavaScript但希望更清楚地了解其与ECMAScript,Web浏览器, Babel等之间关系的人员。 您还将了解有关脚本语言,JavaScript引擎和JavaScript运行时的详细信息。

So get pumped.

因此,抽。

JavaScript / ECMAScript词汇表 (A JavaScript/ECMAScript glossary)

Below is a list of definitions, designed with a focus on consistency and clarity. The definitions are not 100% complete. They are constructed in a way that provides a high-level understanding of the connection and relationship between JavaScript and ECMAScript.

以下是定义的列表,其重点是一致性和清晰度。 定义不是100%完整的。 它们的构造方式可以使您对JavaScript和ECMAScript之间的连接和关系有较高的了解。

Without further ado, let’s get started.

事不宜迟,让我们开始吧。

埃玛国际 (Ecma International)

An organization that creates standards for technologies.

创建技术标准的组织。

To illustrate an example of “standard” (though not one created by Ecma), think of all the keyboards you have ever used. Did the vast majority have letters in the same order, and a space bar, an Enter key, arrow keys, with numbers displayed in a row at the top? This is because most keyboard manufacturers base their keyboard design on the QWERTY layout standard.

为了说明一个“标准”示例(尽管不是由Ecma创建的),请考虑一下您曾经使用过的所有键盘。 绝大多数的字母是否都以相同的顺序排列,是否有空格键,Enter键,箭头键,并在顶部连续显示数字? 这是因为大多数键盘制造商的键盘设计基于QWERTY布局标准。

ECMA-262 (ECMA-262)

This is a standard published by Ecma International. It contains the specification for a general purpose scripting language.

这是Ecma International发布的标准。 它包含通用脚本语言的规范。

ECMA-262 is a standard like QWERTY, but instead of representing a keyboard layout specification, it represents a scripting language specification called ECMAScript.

ECMA-262是类似于QWERTY的标准,但是它不是表示键盘布局规范,而是表示一种称为ECMAScript的脚本语言规范。

Think of ECMA-262 as ECMAScript’s reference number.

将ECMA-262视为ECMAScript的参考编号。

脚本语言 (A scripting language)

A programming language designed specifically for acting on an existing entity or system

专为作用于现有实体或系统而设计的编程语言

For a general idea of what makes a programming language a scripting language, consider the commands “walk”, “run”, and “jump.” These actions require something to carry them out, perhaps a person, a dog, or a video game character. Without an actor to perform these commands, “walk”, “run”, and “jump” wouldn’t make sense. This set of actions is analogous to a scripting language that focuses on manipulating an external entity.

有关使编程语言成为脚本语言的一般概念,请考虑命令“ walk”,“ run”和“ jump”。 这些动作需要执行某些动作,例如人,狗或电子游戏角色。 没有演员来执行这些命令,“走路”,“奔跑”和“跳跃”就没有意义。 这组动作类似于专注于操纵外部实体的脚本语言。

ECMAScript (ECMAScript)

The specification defined in ECMA-262 for creating a general purpose scripting language.Synonym: ECMAScript specification

ECMA-262中定义的用于创建通用脚本语言的规范。 同义词: ECMAScript规范

While ECMA-262 is the name of the standard, it represents the scripting language specification ECMAScript.

ECMA-262是标准的名称,它表示脚本语言规范ECMAScript。

ECMAScript provides the rules, details, and guidelines that a scripting language must observe to be considered ECMAScript compliant.

ECMAScript提供了脚本语言必须遵守的规则,详细信息和准则,才能被视为符合ECMAScript。

JavaScript (JavaScript)

A general purpose scripting language that conforms to the ECMAScript specification.

符合ECMAScript规范的通用脚本语言。

JavaScript is the coffee-flavored language with which I love to program. ECMAScript is the specification it’s based on. By reading the ECMAScript specification, you learn how to create a scripting language. By reading the JavaScript documentation, you learn how to use a scripting language.

JavaScript是我喜欢编程的咖啡味语言。 ECMAScript是它基于的规范。 通过阅读ECMAScript规范 ,您将学习如何创建 一种脚本语言。 通过阅读JavaScript文档 ,您将学习如何使用脚本语言。

When people call JavaScript a “dialect of the ECMAScript language,” they mean it in the same sense as when talking about English, French, or Chinese dialects. A dialect derives most of its lexicon and syntax from its parent language, but deviates enough to deserve distinction.

人们将JavaScript称为“ ECMAScript语言的方言”时,其含义与谈论英语,法语或汉语方言时相同。 方言是从其母语衍生出大部分词典和语法的,但要偏离得足够多,值得加以区别。

JavaScript mostly implements the ECMAScript specification as described in ECMA-262, but a handful of differences do exist. Mozilla outlines JavaScript’s non-ECMAScript language features here:

JavaScript主要实现ECMA-262中描述的ECMAScript规范,但是确实存在一些差异。 Mozilla 在这里概述了JavaScript的非ECMAScript语言功能:

JavaScript引擎 (A JavaScript engine)

A program or interpreter that understands and executes JavaScript code.

理解和执行JavaScript代码的程序或解释器。

Synonyms: JavaScript interpreter, JavaScript implementation

同义词 :JavaScript解释器,JavaScript实现

JavaScript engines are commonly found in web browsers, including V8 in Chrome, SpiderMonkey in Firefox, and Chakra in Edge. Each engine is like a language module for its application, allowing it to support a certain subset of the JavaScript language.

JavaScript引擎通常在网络浏览器中找到,包括Chrome中的V8,Firefox中的SpiderMonkey和Edge中的Chakra。 每个引擎就像其应用程序的语言模块一样,允许它支持JavaScript语言的特定子集。

A JavaScript engine to a browser is like language comprehension to a person. If we re-visit our example of the actions “walk”, “run”, “jump”, a JavaScript engine is the part of an “entity” that actually understands what these actions mean.

浏览器JavaScript引擎就像人的语言理解一样。 如果我们重新查看“行走”,“奔跑”,“跳跃”动作的示例,则JavaScript引擎是“实体”的一部分,它实际上了解这些动作的含义。

This analogy helps to explain a few things about browsers:

这个类比有助于解释有关浏览器的一些事情:

浏览器性能差异 (Differences in browser performance)

Two people may recognize the command “jump”, but one may react to the command faster because the person can understand and process the command faster than the other person. Similarly, two browsers can understand JavaScript code, but one runs it faster because its JavaScript engine is implemented more efficiently.

两个人可能会识别命令“跳跃”,但是一个人可能对命令的React更快,因为一个人比另一个人能更快地理解和处理命令。 同样,两种浏览器都可以理解JavaScript代码,但是一种浏览器可以更快地运行它,因为其JavaScript引擎的实施效率更高。

浏览器支持方面的差异 (Differences in browser support)

Consider the differences that exist between people who speak the same language. Even if many people speak English, some may know some words, expressions, and syntax rules that others don’t, and vice versa. Browsers are the same way. Even though the JavaScript engines of browsers all understand JavaScript, some browsers have a greater understanding of the language than others. There are differences in the way browsers support the language.

考虑说相同语言的人之间存在的差异。 即使许多人说英语,也可能有些人会知道一些其他人不会的单词,表达式和语法规则,反之亦然。 浏览器是相同的方式。 尽管浏览器JavaScript引擎都了解JavaScript,但某些浏览器比其他浏览器对语言的理解要强。 浏览器支持该语言的方式有所不同。

With regards to browser support, people usually talk about “ECMAScript compatibility” rather than “JavaScript compatibility,” even though JavaScript engines parse and execute… well, JavaScript. This can be a little confusing, but there is an explanation.

关于浏览器支持,尽管JavaScript引擎可以解析和执行JavaScript,但人们通常谈论的是“ ECMAScript兼容性”而不是“ JavaScript兼容性”。 这可能有点令人困惑,但是有一个解释。

If you will recall, ECMAScript is a specification for what a scripting language could look like. Releasing a new edition of ECMAScript does not mean that all JavaScript engines in existence suddenly have those new features. It is up to the groups or organizations who are responsible for JavaScript engines to be up-to-date about the latest ECMAScript specification, and to adopt its changes.

如果你还记得,ECMAScript是什么脚本语言可能看起来像一个规范。 发行新版本的ECMAScript并不意味着现有的所有JavaScript引擎都会突然具有这些新功能。 负责JavaScript引擎的小组或组织可以了解最新的ECMAScript规范,并采用其更改。

Therefore, developers tend to ask questions like, “What version of ECMAScript does this browser support?” or “Which ECMAScript features does this browser support?” They want to know if Google, Mozilla, and Microsoft have gotten around to updating their browsers’ JavaScript engines — for example V8, SpiderMonkey, and Chakra, respectively — with the features described in the latest ECMAScript.

因此,开发人员往往会问诸如“此浏览器支持哪种版本的ECMAScript?”之类的问题。 或“此浏览器支持哪些ECMAScript功能?” 他们想知道Google,Mozilla和Microsoft是否能够利用最新的ECMAScript中描述的功能来更新其浏览器JavaScript引擎(例如分别为V8SpiderMonkeyChakra)

The ECMAScript compatibility table is a good resource for answering those questions.

ECMAScript兼容性表是回答这些问题的好资源。

If a new edition of ECMAScript comes out, JavaScript engines do not integrate the entire update at one go. They incorporate the new ECMAScript features incrementally, as seen in this excerpt from Firefox’s JavaScript changelog:

如果出现新版本的ECMAScript,则JavaScript引擎不会一次集成整个更新。 它们逐步地合并了新的ECMAScript功能,如以下从Firefox JavaScript更改日志中摘录所示:

JavaScript运行时 (A JavaScript runtime)

The environment in which the JavaScript code runs and is interpreted by a JavaScript engine.The runtime provides the host objects that JavaScript can operate on and work with.

JavaScript代码在其中运行并由JavaScript引擎解释的环境。运行时提供了可以在JavaScript上进行操作和使用的宿主对象。

Synonyms: Host environment

同义词 主机环境

The JavaScript runtime is the “existing entity or system” mentioned in the scripting language definition. Code passes through the JavaScript engine, and once parsed and understood, an entity or system performs the interpreted actions. A dog walks, a person runs, a video game character jumps (or in the case of the above image, wrecks).

JavaScript运行时是脚本语言定义中提到的“现有实体或系统”。 代码通过JavaScript引擎传递,并且一旦被解析和理解,实体或系统就会执行解释后的动作。 一只狗 走路一个人 奔跑时,视频游戏角色会跳动(或者在上述图片中是残骸)。

Applications make themselves available to JavaScript scripting by providing “host objects” at runtime. For the client side, the JavaScript runtime would be the web browser, where host objects like windows and HTML documents are made available for manipulation.

通过在运行时提供“主机对象”,应用程序可用于JavaScript脚本。 对于客户端,JavaScript运行时将是Web浏览器,其中的宿主对象(例如Windows和HTML文档)可供操作。

Have you ever worked with the window or document host objects? The window and document objects are not actually a part of the core JavaScript language. They are Web APIs, objects provided by a browser acting as JavaScript’s host environment. For the server side, the JavaScript runtime is Node.js. Server-related host objects such as the file system, processes, and requests are provided in Node.js.

您是否曾经使用过窗口或文档宿主对象? 窗口和文档对象实际上并不是核心JavaScript语言的一部分。 它们是Web API,是由充当JavaScript宿主环境的浏览器提供的对象。 对于服务器端,JavaScript运行时为Node.js。 Node.js中提供了与服务器相关的主机对象,例如文件系统,进程和请求。

An interesting point: different JavaScript runtimes can share the same JavaScript engine. V8, for example, is the JavaScript engine used in both Google Chrome and Node.js — two very different environments.

有趣的一点:不同JavaScript运行时可以共享同一个JavaScript引擎。 例如,V8是Google Chrome和Node.js中使用JavaScript引擎,这是两个非常不同的环境。

ECMAScript 6 (ECMAScript 6)

It is the sixth edition of the ECMA-262 standard, and features major changes and improvements to the ECMAScript specification.

它是ECMA-262标准的第六版,对ECMAScript规范进行了重大更改和改进。

Synonyms: ES6, ES2015, and ECMAScript 2015

同义词 :ES6,ES2015和ECMAScript 2015

This edition of ECMAScript changed its name from ES6 to ES2015 because in 2015 Ecma International decided to switch to annual releases of ECMAScript. Accordingly, Ecma International also started to name new editions of the ECMAScript specification based on the year they are released. In short, ES6 and ES2015 are two different names for the same thing.

此版本的ECMAScript的名称从ES6更改为ES2015,因为2015年Ecma International决定改用ECMAScript的年度版本。 因此,Ecma International也开始根据发行年份来命名ECMAScript规范的新版本。 简而言之,ES6和ES2015是同一事物的两个不同名称。

巴别塔 (Babel)

A transpiler that can convert ES6 code to ES5 code.

可以将ES6代码转换为ES5代码的编译器。

Developers can use the shiny new features that come with ES6, but may be concerned with cross-browser compatibility for their web apps. At the time of the writing of this article, Edge and Internet Explorer do not fully support features from the ES6 specification.

开发人员可以使用ES6随附闪亮新功能 ,但可能会担心其Web应用程序的跨浏览器兼容性。 在撰写本文时,Edge和Internet Explorer尚未完全支持ES6规范中的功能。

Concerned developers can use Babel to convert their ES6 code to a functionally equivalent version that only use ES5 features. All of the major browsers fully support ES5, so they can run the code without any issues.

有关开发人员可以使用Babel将其ES6代码转换为功能相同的版本,仅使用ES5功能。 所有主要的浏览器都完全支持ES5,因此它们可以毫无问题地运行代码。

另一个有趣的花絮 (One more interesting tidbit)

I hope you found this information about JavaScript and ECMAScript useful. Before we wrap up things here, I’d like to share one more piece of information that needs to be clarified for fledgling web developers like me.

我希望您发现有关JavaScript和ECMAScript的信息有用。 在这里总结之前,我想分享一些信息,这些信息需要像我这样的新兴Web开发人员加以澄清。

鸡肉或鸡蛋 (Chicken or the egg)

A confusing bit of history is that JavaScript was created in 1996. It was then submitted to Ecma International in 1997 for standardization, which resulted in ECMAScript. At the same time, because JavaScript conformed to the ECMAScript specification, JavaScript is an example of an ECMAScript implementation.

令人困惑的历史是JavaScript于1996年创建。然后在1997年将其提交给Ecma International进行标准化,从而产生了ECMAScript。 同时,由于JavaScript符合ECMAScript规范,因此JavaScript是ECMAScript实现的示例。

That leaves us with this fun fact: ECMAScript is based on JavaScript, and JavaScript is based on ECMAScript.

这给我们留下了一个有趣的事实:ECMAScript基于JavaScript,而JavaScript基于ECMAScript。

I know.

我知道。

It sounds exactly like the time-travel trope of people being their own parent — a little wonky, but kind of fun to think about.

听起来就像是人们成为自己父母的时空旅行的轻快话-有点古怪,但是想起来却很有趣。

一切美好的事物 (All good things)

I know we’ve all had fun here, but that was a lot of information to digest. I’ll take this opportunity to say farewell.

我知道我们在这里都玩得很开心,但这是很多值得消化的信息。 我将借此机会告别。

Please feel free to leave any questions, comments, suggestions, or concerns below.

请随时在下面留下任何问题,评论,建议或疑虑。

Thank you very much for reading!

非常感谢您的阅读!

翻译自: https://www.freecodecamp.org/news/whats-the-difference-between-javascript-and-ecmascript-cba48c73a2b5/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值