JavaScript 是用什么语言编写的?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7005729/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What language is JavaScript written in?
提问by Sergio
If it's a scripting language as the name implies it must be written in a lower level language right? Like how PHP is written in C what language is JavaScript written in?
如果它是一种脚本语言,顾名思义,它必须用较低级别的语言编写,对吗?比如 PHP 是如何用 C 编写的,JavaScript 是用什么语言编写的?
回答by Seth Carnegie
Javascript is just a standard, more formally known as ECMAScript. It can be implemented in any language, just like any standard.
Javascript 只是一个标准,更正式地称为ECMAScript。它可以用任何语言实现,就像任何标准一样。
Chrome's Javascript engine, V8, is written in C++.
Chrome 的 Javascript 引擎V8是用 C++ 编写的。
From the project page:
从项目页面:
V8 is written in C++ and is used in Google Chrome, the open source browser from Google.
V8 implements ECMAScript as specified in ECMA-262, 5th edition, and runs on Windows (XP or newer), Mac OS X (10.5 or newer), and Linux systems that use IA-32, x64, or ARM processors.
V8 是用 C++ 编写的,并在 Google Chrome(Google 的开源浏览器)中使用。
V8 实现了 ECMA-262,第 5 版中指定的 ECMAScript,并在使用 IA-32、x64 或 ARM 处理器的 Windows(XP 或更高版本)、Mac OS X(10.5 或更高版本)和 Linux 系统上运行。
Firefox's Javascript engine, SpiderMonkey(and now TraceMonkey) is also written in C++. And as maerics below said, Rhinois written in Java.
Firefox 的 Javascript 引擎SpiderMonkey(现在是 TraceMonkey)也是用 C++ 编写的。正如下面的 maerics 所说,Rhino是用 Java 编写的。
回答by Matthew Crumley
All the answers so far are correct, but since it hasn't been mentioned yet, JavaScript can be written in JavaScript.
到目前为止,所有答案都是正确的,但由于尚未提及,因此可以使用 JavaScript 编写 JavaScript。
回答by gf3
Most Javascript interpreters are written in C/C++ (V8, Nitro, etc…), however a compliant interpreter can be written in any language (Rhino→Java, Interpreter→Javascript, etc…).
大多数 Javascript 解释器是用 C/C++ 编写的(V8、Nitro 等……),但是兼容的解释器可以用任何语言编写(Rhino→Java、解释器→Javascript 等……)。
回答by Tom Studee
Whichever language the client webbrowsers javascript interpreter was written in :)
无论客户端浏览器 javascript 解释器是用哪种语言编写的 :)
回答by dfreeman
Javascript is an implementation of the ECMAScriptstandard, but there is no singular canonical interpreter like you see with PHP.
Javascript 是ECMAScript标准的实现,但没有像您在 PHP 中看到的那样单一的规范解释器。
Most of the major implementations (standalone or as parts of web browsers) out there tend to be largely written in C or C++ for performance reasons, but that's not necessarily always the case. Rhino, an engine maintained by Mozilla, is written in Java.
出于性能原因,大多数主要实现(独立的或作为 Web 浏览器的一部分)往往主要用 C 或 C++ 编写,但情况并非总是如此。Rhino 是 Mozilla 维护的引擎,是用 Java 编写的。
回答by Rients Dijkstra
Most implementations of Javascript show behaviour that is clearly caused by the use of pointers and byref parameter passing, which normally points towards the use of C, or C++
大多数 Javascript 实现显示的行为显然是由使用指针和 byref 参数传递引起的,通常指向使用 C 或 C++
This is clearly notable for instance when you are taking apart a multidimensional array in a loop, with the help of intermediate array's. These tend to behave very "strangely", if you are not familiar with pointers and byref passing of parameters (You need do var hlp = new Array() each time or it will overwrite the previous values which you already stored somewhere else)
例如,当您在中间数组的帮助下在循环中拆分多维数组时,这显然是值得注意的。如果您不熟悉指针和参数的byref 传递,这些往往表现得非常“奇怪”(您每次都需要执行 var hlp = new Array() 否则它会覆盖您已经存储在其他地方的先前值)
I'm rather curious as to how an implementation of javascript in for instance Java, because I imagine that this kind of behaviour will be quite different in that case?
我很好奇如何在例如 Java 中实现 javascript,因为我认为这种行为在那种情况下会大不相同?
回答by Rients Dijkstra
C++
is the fundamental language for anything modern and fancy. Most modern high level languages are subset of low level language,C++
. All modern languages you see today is a subset of C++
someway or the other. Even Java
is a subset of C++
.
C++
是任何现代和奇特事物的基本语言。大多数现代高级语言都是低级语言的子集,C++
. 你今天看到的所有现代语言都是某种方式的一个子集C++
。EvenJava
是 的子集C++
。