是否有一个 javaScript 引擎可以让我在不被迫使用浏览器的情况下运行我的代码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6223649/
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
Is there a javaScript engine where I can run my code without being forced to use a browser?
提问by pencilCake
Is there any way to write and run a JavaScript code without having a need to run a browser and use its JavaScript engine?
有没有什么方法可以编写和运行 JavaScript 代码而无需运行浏览器并使用其 JavaScript 引擎?
Thanks!
谢谢!
回答by Cheeso
I am amazed no one has pointed this out yet.
我很惊讶还没有人指出这一点。
Windows includes a Javascript engine that can be used from the command line.
Windows 包含一个可以从命令行使用的 Javascript 引擎。
All versions of Windows, since Windows 98, have included something called "The Windows Script Host". It's a windows-standard way to support script "engines". Since the first release, WSH supports JScript, Microsoft's version of Javascript. Among other things, this means that, from a windows command line, you can just invoke the name of any *.js file, and it will run in the JScript engine. (via either wscript.exe or cscript.exe)
自 Windows 98 以来,所有版本的 Windows 都包含称为“ Windows 脚本宿主”的内容。这是支持脚本“引擎”的 Windows 标准方式。从第一个版本开始,WSH 就支持 JScript,Microsoft 的 Javascript 版本。除此之外,这意味着,从 Windows 命令行,您可以调用任何 *.js 文件的名称,并且它将在 JScript 引擎中运行。(通过 wscript.exe 或 cscript.exe)
You can see this question: What is the ProgId or CLSID for IE9's Javascript engine (code-named "Chakra")to learn how to invoke the higher-performance IE9 Javascript engine from cscript.exe.
你可以看到这个问题: 什么是IE9的Javascript引擎(代号为“Chakra”)的ProgId或CLSID,了解如何从cscript.exe调用更高性能的IE9 Javascript引擎。
I use cscript.exe to run jslint from within emacs, on any .js module I'm editing. (via flymake-for-js) Lots of people use .js modules to do system maintenance or administration.
我使用 cscript.exe 从 emacs 中在我正在编辑的任何 .js 模块上运行 jslint。(通过 flymake-for-js)很多人使用 .js 模块来进行系统维护或管理。
回答by Param
Java 6 has support for executing JavaScript within Java code. You can load any arbitrary JS file and execute (eval) it.
Java 6 支持在 Java 代码中执行 JavaScript。您可以加载任意 JS 文件并执行(评估)它。
Here's a simple code example for the same: http://www.java2s.com/Code/Java/JDK-6/ExecuteJavascriptscriptinafile.htm
这是一个简单的代码示例:http: //www.java2s.com/Code/Java/JDK-6/ExecuteJavascriptscriptinafile.htm
回答by drhanlau
On top of that, you can take a look at jslib http://code.google.com/p/jslibs/which uses spidermonkey, the core of javascript engine in firefox.
最重要的是,您可以查看 jslib http://code.google.com/p/jslibs/,它使用spidermonkey,它是 firefox 中 javascript 引擎的核心。
回答by bbg
回答by Khepri
Might as well throw Google's V8 engineinto the ring
不妨把谷歌的V8 引擎扔进戒指
Please see JasonMP85's answerfor a few more options as well.
有关更多选项,请参阅JasonMP85 的回答。
回答by OnesimusUnbound
There are tons of independent, js engines, adding to previous post
有大量独立的 js 引擎,添加到以前的帖子中
- JSDB, http://www.jsdb.org/
- Narwhaljs, http://narwhaljs.org/
- JSDB,http://www.jsdb.org/
- 独角鲸,http://narwhaljs.org/
There are tons of standalone JS engines and framework built on top of them (Node.js, ringojs, etc.)
有大量独立的 JS 引擎和构建在它们之上的框架(Node.js、ringojs 等)
http://en.wikipedia.org/wiki/Comparison_of_server-side_JavaScript_solutions
http://en.wikipedia.org/wiki/Comparison_of_server-side_JavaScript_solutions
Well, all you need is to choose based on what you need.
好吧,您所需要的只是根据您的需要进行选择。