有没有像 JavaScript 编译器这样的东西?

发布于 2024-11-27 22:59:49 字数 210 浏览 1 评论 0原文

我想知道是否可以编写一个 javascript 程序并将其编译并链接到可执行文件中?

如果是这样,是否有可能创建一个与 c/c++ 世界的 libc 等效的 libjs?创建这样的东西不会使 javascript 成为一种成熟的语言,然后可以直接在目标硬件上编译和运行吗?

如果你有一个 javascript 编译器,你就不能用 javascript 编写一个新的编译器吗?

I'm wondering if its possible to write a javascript program and have it compiled and linked into an executable?

If so would it be possible to create a libjs that would be the equivalent of libc for the c/c++ world? wouldn't creating something like this make javascript a full fledged language that could then be compiled and run directly on the target hardware?

If you had a compiler for javascript, couldn't you write a new compiler in javascript?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

唠甜嗑 2024-12-04 22:59:49

是的,你可以写一个js编译器。不确定它有多受欢迎:

  1. 现在 js 引擎非常快,所以你没有获得太多速度。

  2. 这将是特定于平台的,或者您必须支持多个平台。不太令人愉快。

  3. 它有什么用?解释型语言的伟大之处在于它不需要编译。它缩短了开发周期和构建时间(曾经坐在 C 程序前面,不得不更改整个项目所依赖的文件,并且必须运行并重新运行 make ,这需要几分钟才能编译所有内容? ).

关于你的最后一点,你是对的。如果你有这些编译器之一,你确实可以用 javascript 编写另一个。

Yes, you could write a js compiler. Not sure how popular it would be:

  1. js engines are very fast these days, so you're not gaining much speed.

  2. It would be platform specific, or you would have to support multiple platforms. Not pleasant.

  3. What would it be useful for? The great thing about an interpreted language is the very fact that it doesn't need to be compiled. It shortens development cycles and build times (ever sat in front of a C program and had to change a file that the entire project relies on and had to run and rerun makes that take minutes to compile everything?).

Regarding your last point, you're correct. Had you one of these compilers, you could indeed write another one in javascript.

究竟谁懂我的在乎 2024-12-04 22:59:49

阅读 ...并且不要错过评论。

这里还有一些选项。

Read this ... and do not miss the comments.

Here are also some options.

祁梦 2024-12-04 22:59:49

是的,你有一个叫做Google Closure Compiler的东西,但它不是传统意义上的编译器,它不会将javascript转换为机器代码,而是将javascript转换为高度优化的javascript。它实际上是一个优化编译器。编译器还运行一些测试来检测拼写错误等错误,就像工具 JSLint 一样。但 Google 建议在 Closure 库中编写的 javascript 上使用此编译器。有关 Closure Compiler 的详细信息,请参阅

但我不认为将客户端 javascript 编译为机器代码是一个好主意,因为机器代码是机器相关的,因此在将 javascript 发送到客户端之前,您必须检测其操作系统及其处理器架构。所以这将变得像 linux 上的 javascipt for firefox、windows 上的 javascipt for firefox、x86 上的 javascipt for firefox 等

Yes you have something called Google Closure Compiler but its not a compiler in the conventional sense,it doesnt convert javascript into machine code but converts javascript into javascript but highly optimized javascript. Its actually an optimizing compiler.Also the compiler runs some tests to detect errors like typos much like the tool JSLint.But Google advises to use this compiler on javascript written in Closure Library. see this for more on Closure Compiler.

But i dont think compiling client-side javascript to machine code is a good idea because machine code is machine dependent so then before you send javascript to the client you have to detects its OS and its processor architecture. So this would become like javascipt for firefox on linux,javascipt for firefox on windows,javascipt for firefox on x86,etc

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文