简体   繁体   中英

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

I was looking at elm: https://guide.elm-lang.org/

I see this type of phrase on some languages/frameworks: X is a language that compiles to JavaScript.

Does language X literally compile to another interpreted language? (I would see JS) Or Bytecode of that language? (I would see bytes/hex etc.)

If compiled to JS - would that mean the code can only go as fast as JS does ? (a lot of frameworks/languages tout how fast they are)

I'm new-ish, sorry if its a dumb q

Does language X literally compile to another interpreted language?

Yes, that's correct. You write code in elm, and then compile it into the equivalent javascript code. 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)

If compiled to JS - would that mean the code can only go as fast as JS does? (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.

Does language X literally compile to another interpreted language?

Yes, indeed. 'Transpilation' is the actual term of transforming one high-level language into another.

If compiled to JS - would that mean the code can only go as fast as JS does? (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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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