JavaScript: Standalone compiler or interpreter for Windows?
What are the JavaScript compilers or interpreters available for Windows?
I read the book Eloquent JavaScript recently. 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.
The compiler or interpreter should be easily available as a pre-compiled binary that 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.
Nobody has mentioned yet, window's own javascript compiler: 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.
The compiler is capable of compiling javascript files into executables that can run on any windows machine with .NET installed.
Node.js works 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 documented with a large selection of official and third party modules.
It does require cygwin to 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.
There are several free standalone Javascript interpreters available:
- V8 - This is the same Javascript engine used in the Chrome browser.
- SpiderMonkey - From Mozilla.
- Rhino - A Javascript implementation on Java.
jsdb is nice. I use it within editplus, sometimes within Aptana Studio
Ok, Windows Scripting Host is tool for performing various administrative tasks using Microsoft's Active Scripting and 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
Forget about compiler, BTW, ECMAScript is interpreted language (JIT compiling is the other issue)
Also, note that ECMAScript standard does not define any standard I/O, so the host program is responsible for providing it.
You can also, under some circumstances run JScript scripts (Microsoft's Javascript implementation) directly on the command prompt.
But my personal favourite is Rhino, mentioned in the other answer.
Perhaps a bit convoluted for what you're looking for but you can use Rhino's JavaScript Compiler to 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.
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.exe command.
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.
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 FalsyValues conference in Warsaw next month - link.
精彩评论