gpt4 book ai didi

Javascript - 编译语言?

转载 作者:行者123 更新时间:2023-11-29 21:55:21 27 4
gpt4 key购买 nike

我是 Web 开发新手,正在学习 JavaScript。

来自course在斯坦福:

JavaScript is an interpreted language, not a compiled language. A program such as C++ or Java needs to be compiled before it is run. The source code is passed through a program called a compiler, which translates it into bytecode that the machine understands and can execute. In contrast, JavaScript has no compilation step. Instead, an interpreter in the browser reads over the JavaScript code, interprets each line, and runs it. More modern browsers use a technology known as Just-In-Time (JIT) compilation, which compiles JavaScript to executable bytecode just as it is about to run.

来自 You Don't Know JS: Scope & Closures 通过 Kyle Simpson :

... but despite the fact that JavaScript falls under the general category of “dynamic” or “interpreted” languages, it is in fact a compiled language.

Let’s just say, for simplicity sake, that any snippet of JavaScript has to be compiled before (usually right before!) it’s executed. So, the JS compiler will take the program var a = 2; and compile it first, and then be ready to execute it, usually right away.

从 Stack Overflow 的一些问题中,有一些想法,例如:它取决于语言的实际实现。

你有什么想法吗?

最佳答案

Chrome 浏览器使用 V8 引擎编译 Javascript,就像其他浏览器可能使用 Rhino 或 SpiderMonkey 一样。

V8 是谷歌用 C++ 编写的 JavaScript 引擎。它用于在客户端 (Google Chrome) 和服务器端 (node.js) 应用程序中编译 JS。为了获得速度,V8 将 JavaScript 代码翻译成更高效的机器代码,而不是使用解释器。

V8 通过实现 JIT(即时)编译器在脚本执行时将 JavaScript 代码编译为机器代码,就像许多现代 JavaScript 引擎(例如 SpiderMonkey 或 Rhino (Mozilla))正在做的那样。与 V8 的主要区别在于它不生成字节码或任何中间代码。它只是即时编译 JavaScript。

希望这对您有所帮助!

关于Javascript - 编译语言?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26709524/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com