简体   繁体   English

当框架/库说“编译为 Javascript”时是什么意思?

[英]What is meant when a framework/library says "compile to Javascript"?

I was looking at elm: https://guide.elm-lang.org/我在看榆树: https://guide.elm-lang.org/

I see this type of phrase on some languages/frameworks: X is a language that compiles to JavaScript.我在某些语言/框架上看到这种类型的短语: X is a language that compiles to JavaScript.

Does language X literally compile to another interpreted language?语言 X 从字面上编译成另一种解释语言吗? (I would see JS) Or Bytecode of that language? (我会看到 JS)还是那种语言的字节码? (I would see bytes/hex etc.) (我会看到字节/十六进制等)

If compiled to JS - would that mean the code can only go as fast as JS does ?如果编译为 JS - 这是否意味着代码只能像 JS 一样快 go (a lot of frameworks/languages tout how fast they are) (很多框架/语言都在吹嘘它们有多快)

I'm new-ish, sorry if its a dumb q我是新手,对不起,如果它是一个愚蠢的q

Does language X literally compile to another interpreted language?语言 X 从字面上编译成另一种解释语言吗?

Yes, that's correct.对,那是正确的。 You write code in elm, and then compile it into the equivalent javascript code.您在 elm 中编写代码,然后将其编译为等效的 javascript 代码。 It needs to be in javascript, because that's what the browser understands ( WebAssembly does exist, so javascript isn't technically the only option, but not everything is designed with WebAssembly in mind)它需要在 javascript 中,因为这是浏览器所理解的( WebAssembly确实存在,所以 javascript 在技术上并不是唯一的选择,但并非所有东西都是在设计时考虑到 WebAssembly)

If compiled to JS - would that mean the code can only go as fast as JS does?如果编译为 JS - 这是否意味着代码只能像 JS 一样快 go ? (a lot of frameworks/languages tout how fast they are) (很多框架/语言都在吹嘘它们有多快)

Yes.是的。 Though it could allow you to write high quality, efficient javascript code more easily, which is generally what they mean when they say it's fast.尽管它可以让您更轻松地编写高质量、高效的 javascript 代码,这通常是他们所说的快速的意思。

Does language X literally compile to another interpreted language?语言 X 从字面上编译成另一种解释语言吗?

Yes, indeed.确实是的。 'Transpilation' is the actual term of transforming one high-level language into another. “Transpilation”是将一种高级语言转换为另一种语言的实际术语。

If compiled to JS - would that mean the code can only go as fast as JS does?如果编译为 JS - 这是否意味着代码只能像 JS 一样快 go ? (a lot of frameworks/languages tout how fast they are) (很多框架/语言都在吹嘘它们有多快)

In the course of transpilation, the transpilers usually apply optimizations to produce highly efficient JavaScript that has the potential to be way faster than the average handwritten JavaScript.在转译过程中,转译器通常会进行优化以产生高效的 JavaScript,它有可能比普通的手写 JavaScript 更快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM