JavaScript:Windows 的独立编译器或解释器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5742128/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 18:38:58  来源:igfitidea点击:

JavaScript: Standalone compiler or interpreter for Windows?

javascriptwindows

提问by Ashwin Nanjappa

What are the JavaScriptcompilers or interpreters available for Windows?

有哪些适用于WindowsJavaScript编译器或解释器?

I read the book Eloquent JavaScriptrecently. This book introduces the reader to programming using JavaScript as the first language. Sadly, the programs are restricted to run inside the browser embedded in HTML. So, I wonder if it is possible to write JavaScript programs that can be executed standalone.

我最近阅读了Eloquent JavaScript一书。本书向读者介绍了使用 JavaScript 作为第一语言进行编程。遗憾的是,这些程序只能在嵌入 HTML 的浏览器中运行。所以,我想知道是否有可能编写可以独立执行的 JavaScript 程序。

The compiler or interpreter should be easily available as a pre-compiled binarythat can be downloaded and installed by a beginner. He should be able to write simple standalone JavaScript programs that are compiled with this compiler. Additional JavaScript libraries, frameworks, IDEs and debugging support that would work with this compiler would be a plus.

编译器或解释器应该作为预编译的二进制文件很容易获得,初学者可以下载和安装。他应该能够编写使用此编译器编译的简单独立 JavaScript 程序。与此编译器配合使用的其他 JavaScript 库、框架、IDE 和调试支持将是一个加分项。

回答by Alex Barrett

Node.jsworks well as an interpreter, even if you do not choose to use it for web applications. It is a framework that runs on the V8 JavaScript engine. It is well documentedwith a large selection of official and third party modules.

Node.js可以很好地用作解释器,即使您不选择将它用于 Web 应用程序。它是一个运行在 V8 JavaScript 引擎上的框架。这是有据可查的有一个大的选择官方和第三方模块

It does require cygwinto run on Windows though (or you can compile it with MingW). There are precompiled binaries, including the required cygwin libraries, available at node-js.prcn.co.cc.

不过,它确实需要 cygwin才能在 Windows 上运行(或者您可以使用 MingW 编译它)。node-js.prcn.co.cc提供了预编译的二进制文件,包括所需的 cygwin 库。

回答by Billy Moon

Nobody has mentioned yet, window's own javascript compiler: http://msdn.microsoft.com/en-us/library/vstudio/7435xtz6(v=vs.100).aspx

还没有人提到,window 自己的 javascript 编译器:http: //msdn.microsoft.com/en-us/library/vstudio/7435xtz6(v=vs.100).aspx

Microsoft (R) JScript Compiler version 8.00.50727
for Microsoft (R) .NET Framework version 2.0.50727
Copyright (C) Microsoft Corporation 1996-2005. All rights reserved.

jsc [options] <source files> [[options] <source files>...]

                         JScript Compiler Options

                           - OUTPUT FILES -
  /out:<file>              Specify name of binary output file
  /t[arget]:exe            Create a console application (default)
  /t[arget]:winexe         Create a windows application
  /t[arget]:library        Create a library assembly
  /platform:<platform>     Limit which platforms this code can run on; must be x86, Itanium, x64, or anycpu, which is the default

                           - INPUT FILES -
  /autoref[+|-]            Automatically reference assemblies based on imported namespaces and fully-qualified names (on by default)
  /lib:<path>              Specify additional directories to search in for references
  /r[eference]:<file list> Reference metadata from the specified assembly file
                           <file list>: <assembly name>[;<assembly name>...]

                           - RESOURCES -
  /win32res:<file>         Specifies Win32 resource file (.res)
  /res[ource]:<info>       Embeds the specified resource
                           <info>: <filename>[,<name>[,public|private]]
  /linkres[ource]:<info>   Links the specified resource to this assembly
                           <info>: <filename>[,<name>[,public|private]]

                           - CODE GENERATION -
  /debug[+|-]              Emit debugging information
  /fast[+|-]               Disable language features to allow better code generation
  /warnaserror[+|-]        Treat warnings as errors
  /w[arn]:<level>          Set warning level (0-4)

                           - MISCELLANEOUS -
  @<filename>              Read response file for more options
  /?                       Display help
  /help                    Display help
  /d[efine]:<symbols>      Define conditional compilation symbol(s)
  /nologo                  Do not display compiler copyright banner
  /print[+|-]              Provide print() function

                           - ADVANCED -
  /codepage:<id>           Use the specified code page ID to open source files
  /lcid:<id>               Use the specified LCID for messages and default code page
  /nostdlib[+|-]           Do not import standard library (mscorlib.dll) and change autoref default to off
  /utf8output[+|-]         Emit compiler output in UTF-8 character encoding
  /versionsafe[+|-]        Specify default for members not marked 'override' or 'hide'

There are usually a couple of copies lying around on any windows install, but they are not usually in the path, so you have to find them.

在任何 Windows 安装中通常都有几个副本,但它们通常不在路径中,因此您必须找到它们。

The compiler is capable of compiling javascript files into executables that can run on any windows machine with .NET installed.

编译器能够将 javascript 文件编译成可执行文件,这些文件可以在任何安装了 .NET 的 Windows 机器上运行。

回答by MAK

There are several free standalone Javascript interpreters available:

有几个免费的独立 Javascript 解释器可用:

  1. V8- This is the same Javascript engine used in the Chrome browser.
  2. SpiderMonkey- From Mozilla.
  3. Rhino- A Javascript implementation on Java.
  1. V8- 这与 Chrome 浏览器中使用的 Javascript 引擎相同。
  2. SpiderMonkey- 来自 Mozilla。
  3. Rhino- Java 上的 Javascript 实现。

回答by Boldewyn

You can also, under some circumstancesrun JScript scripts (Microsoft's Javascript implementation) directly on the command prompt.

某些情况下,您还可以直接在命令提示符运行 JScript 脚本(Microsoft 的 Javascript 实现)。

But my personal favourite is Rhino, mentioned in the other answer.

但我个人最喜欢的是 Rhino,在另一个答案中提到过。

回答by KooiInc

jsdbis nice. I use it within editplus, sometimes within Aptana Studio

jsdb不错。我在editplus 中使用它,有时在Aptana Studio 中使用它

回答by user422039

Ok, Windows Scripting Host is tool for performing various administrative tasks using Microsoft's Active Scriptingand can run scripts in various languages, including JScript, their ECMAScript implementation. There is no much else to say about it, so point your browser to the reference - http://msdn.microsoft.com/en-us/library/shzd7dy4(VS.85).aspx

好的,Windows Scripting Host 是使用 Microsoft 的Active Scripting执行各种管理任务的工具,可以运行各种语言的脚本,包括 JScript,它们的 ECMAScript 实现。关于它没有什么可说的,所以将您的浏览器指向参考 - http://msdn.microsoft.com/en-us/library/shzd7dy4(VS.85).aspx

Forget about compiler, BTW, ECMAScript is interpreted language (JIT compiling is the other issue)

忘记编译器,顺便说一句,ECMAScript 是解释性语言(JIT 编译是另一个问题)

Also, note that ECMAScript standard does not define any standard I/O, so the host program is responsible for providing it.

另请注意,ECMAScript 标准并未定义任何标准 I/O,因此宿主程序负责提供它。

回答by js_masher

I also had the same need but eventually found an app called DeskJS (https://deskjs.wordpress.com). It's a free and portable Windows console application that lets you run pure JavaScript code and even load any existing JS files. It supports the basic JS popup boxes implemented in browsers. You can save your commands as JS files that can be run on startup or by dragging-and-dropping them on the app. Plus there's so much more to it like you can create a build system for Sublime Text that can run JS files via cmd, it supports themes for customizing the entire console and snippets which let you save short snippets of JavaScript code for later use. Improvements are still being made on the app together with other native APIs being included.

我也有同样的需求,但最终找到了一个名为 DeskJS(https://deskjs.wordpress.com)的应用程序。它是一个免费且可移植的 Windows 控制台应用程序,可让您运行纯 JavaScript 代码,甚至可以加载任何现有的 JS 文件。它支持在浏览器中实现的基本 JS 弹出框。您可以将命令保存为 JS 文件,这些文件可以在启动时运行或通过将它们拖放到应用程序上来运行。此外,它还有更多功能,例如您可以为 Sublime Text 创建一个构建系统,该系统可以通过 cmd 运行 JS 文件,它支持自定义整个控制台和代码段的主题,让您可以保存 JavaScript 代码的简短片段以供以后使用。该应用程序仍在进行改进,并包括其他本机 API。

回答by maerics

Perhaps a bit convoluted for what you're looking for but you can use Rhino's JavaScript Compilerto compile JavaScript source code into Java class files which can then be compiled to binary executable programs using the standard GCJ frontend to the GCC compiler suite.

也许您要查找的内容有点复杂,但您可以使用Rhino 的 JavaScript 编译器将 JavaScript 源代码编译为 Java 类文件,然后使用GCC 编译器套件的标准GCJ 前端将其编译为二进制可执行程序。

As mentioned by others, the JScript implementation of ECMAScript is available by default on modern Windows installations. Files with a ".js" extension can be double-click executed or run on the command-line using the cscript.execommand.

正如其他人提到的,ECMAScript 的 JScript 实现在现代 Windows 安装中默认可用。带有“.js”扩展名的文件可以双击执行或使用cscript.exe命令在命令行上运行。

回答by qqryq

Have you tried Mozilla XUL & XULRunner? It is quite more complex than being just an interpreter but it runs also on MacOsX & Linux, not only Windows. Firefox and Thunderbird are written using it (yes, Firefox is written in Javascript!). There will be XUL workshop on FalsyValuesconference in Warsaw next month - link.

你试过Mozilla XUL 和 XULRunner吗?它比只是一个解释器要复杂得多,但它也可以在 MacOsX 和 Linux 上运行,而不仅仅是 Windows。Firefox 和 Thunderbird 是使用它编写的(是的,Firefox 是用 Javascript 编写的!)。下个月在华沙举行关于FalsyValues会议的XUL 研讨会-链接