适用于 Windows 的 Javascript 控制台,如 JSC
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4829266/
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
Javascript Console for Windows like JSC
提问by Shyam
I have to work on the Windows platform for a project, and I happen to do that project with server-sidejavascript (yes, I am actually using server-sidejavascript). Most of my analysis and research I do by working with JSC on my Mac, which allows me to write code and get back a response from the interpreter and load .js files. Now I have been googling and I find most of the results about Firebug or online tools. However, I am looking for something more commandlinish.
我必须在 Windows 平台上为一个项目工作,而我恰好使用服务器端javascript来完成该项目(是的,我实际上使用的是服务器端javascript)。我的大部分分析和研究都是通过在 Mac 上使用 JSC 来完成的,这使我可以编写代码并从解释器获取响应并加载 .js 文件。现在我一直在谷歌搜索,我找到了大部分关于 Firebug 或在线工具的结果。但是,我正在寻找更具命令性的东西。
Does anyone have a good recommendation for a JavaScript interpreter/console application for the Windows platform that does not require a browser and can be run from the commandline (and supports the loading of external .js files) ?
有没有人对 Windows 平台的 JavaScript 解释器/控制台应用程序有很好的推荐,它不需要浏览器并且可以从命令行运行(并支持加载外部 .js 文件)?
Many thanks,
非常感谢,
采纳答案by Ravikiran
http://www.phpied.com/javascript-shell-scripting/-> this might help your cause.
http://www.phpied.com/javascript-shell-scripting/-> 这可能有助于您的事业。
Rhino Shell - https://developer.mozilla.org/en/Rhino_Shell
Rhino Shell - https://developer.mozilla.org/en/Rhino_Shell
回答by zvolkov
node.jshas a Windows version. The installer is completely non-invasive, all it does is copies files to Program Files and adds the path to your system $PATH env. variable. If you then start node.exe without parameters it works as a REPL Javascript console.
node.js有一个 Windows 版本。安装程序是完全非侵入性的,它所做的只是将文件复制到 Program Files 并将路径添加到您的系统 $PATH env。多变的。如果您随后启动不带参数的 node.exe,它将作为 REPL Javascript 控制台工作。
You can load a .js file like this:
您可以像这样加载 .js 文件:
> .load ./file/to/myscript.js
Check out REPL page in Node.js manualfor more info.
查看Node.js 手册中的 REPL 页面以获取更多信息。
回答by sstur
If you don't want to install any external tools, you can use Windows built in cscript.exe and a short script to read/eval/print/loop as follows:
如果你不想安装任何外部工具,你可以使用 Windows 内置的 cscript.exe 和一个简短的脚本来读取/评估/打印/循环,如下所示:
try {
throw {};
} catch(repl) {
while (repl.line != '.exit') {
if (repl.line) {
repl.err = null;
try {
repl.out = eval('(' + repl.line + ')');
} catch (e) {
if (e instanceof SyntaxError) {
try {
repl.out = eval(repl.line);
} catch (e) {
repl.err = e;
}
} else {
repl.err = e;
}
}
if (repl.err) {
WScript.stdout.writeLine('Error: ' + repl.err.message);
} else {
WScript.stdout.writeLine(repl.out == null ? String(repl.out) : (typeof repl.out.toString == 'function' ? repl.out.toString() : Object.prototype.toString.call(repl.out)));
}
}
WScript.stdout.write('> ');
repl.line = WScript.stdin.readLine();
}
}
Save that as repl.js and run cscript repl.js
to get a console similar to jsc.
将其另存为 repl.js 并运行cscript repl.js
以获取类似于 jsc 的控制台。
回答by ifree
if your java runtime >=1.5 ,you can try jrunscript
. It is based on java scriptengines, JavaScript is the default language supported.
如果您的 java 运行时 >=1.5 ,您可以尝试jrunscript
。它基于 java 脚本引擎,JavaScript 是默认支持的语言。
回答by Ron Klein
Not exactly equivalent to JSC, but still..
不完全等同于 JSC,但仍然..
I use the browser's development tools (F12), and there I enter the Consoletab. That's it.
Works with modern browsers, where Firefox usually needs Firebug for this.
我使用浏览器的开发工具 ( F12),然后进入控制台选项卡。就是这样。
适用于现代浏览器,其中 Firefox 通常需要 Firebug 来实现。
The main advantage is to have an interactive interpreter, without the need to load a real file.
主要优点是具有交互式解释器,无需加载真实文件。
回答by Andz
Apart from Node.js, JSDBis quite nice. I checked node.js again and I believe it is now availableas a single executable, node.exe, which is even more compact than JSDB. So I might be using that instead.
除了 Node.js,JSDB还不错。我再次检查了 node.js,我相信它现在可以作为单个可执行文件 node.exe 使用,它比 JSDB 更紧凑。所以我可能会使用它。
回答by js_masher
Just check out DeskJS (https://deskjs.wordpress.com). It's exactly what you're looking for! It's a portable Windows console application that lets you run pure JavaScript code and even load any existing JS files. It supports even 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 and snippets e.t.c...
只需查看 DeskJS ( https://deskjs.wordpress.com)。这正是您要找的!它是一个可移植的 Windows 控制台应用程序,可让您运行纯 JavaScript 代码,甚至可以加载任何现有的 JS 文件。它甚至支持在浏览器中实现的基本 JS 弹出框。您可以将命令保存为 JS 文件,这些文件可以在启动时运行或通过将它们拖放到应用程序上来运行。此外,还有更多功能,例如您可以为 Sublime Text 创建一个构建系统,该系统可以通过 cmd 运行 JS 文件,它支持主题和片段等。