macos 如何在 OS X 上安装 Javascript 运行时解释器?

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

How do I get a Javascript runtime interpreter installed on OS X?

javascriptmacosterminal

提问by wide_eyed_pupil

With OS X Xcode installed one can run ruby code in terminal with ">ruby somefile.rb" command (or from inside TextWrangler with the run command). You can also run a ruby interpreter from in terminal and type code in single lines while the interpreter retains variable objects.

安装 OS X Xcode 后,可以使用“>ruby somefile.rb”命令(或使用 run 命令从 TextWrangler 内部)在终端中运行 ruby​​ 代码。您还可以在终端中运行 ruby​​ 解释器并在解释器保留变量对象的同时在单行中键入代码。

Want same possibilities for Javascript. What must I install (if anything) on OS X to have that functionality? Not looking for an IDE as such just an interpreter that will run in Terminal.app?

想要 Javascript 的相同可能性。我必须在 OS X 上安装什么(如果有的话)才能拥有该功能?不寻找这样的 IDE 只是一个将在 Terminal.app 中运行的解释器?

I assume this is an allowed question for Stackoverflow based on other allowed questions about IDEs for various languages like: What's a good IDE for Python on Mac OS X?

我认为这是 Stackoverflow 允许的问题,基于其他有关各种语言的 IDE 的允许问题,例如: Mac OS X 上 Python 的好 IDE 是什么?

回答by mttrb

There is a Javascript interpreter in the JavaScriptCore framework that comes with OS X. The interpreter is called jsc and can be found at the following path:

OS X自带的JavaScriptCore框架中有一个Javascript解释器,这个解释器叫做jsc,可以在以下路径找到:

/System/Library/Frameworks/JavaScriptCore.framework/Resources/jsc

There is a built-in function, quit(), which will exit interactive mode.

有一个内置函数 ,quit()它将退出交互模式。

If you want to make it easier to use I suggest creating a symlink to a location in your path, e.g.:

如果您想让它更易于使用,我建议创建指向路径中某个位置的符号链接,例如:

sudo ln -s /System/Library/Frameworks/JavaScriptCore.framework/Resources/jsc /usr/local/bin

This will put a symbolic link in /usr/local/bin.

这将在/usr/local/bin.

回答by Kornel

Node.js. It's the V8 engine + libraries + REPL.

节点.js。它是 V8 引擎 + 库 + REPL。

Although Node is usually used for web/network-related applications, at its core it's just a plain JS engine and can even be used for shell scripting.

虽然 Node 通常用于 web/网络相关的应用程序,但它的核心只是一个普通的 JS 引擎,甚至可以用于 shell 脚本。

You can install it from the installer, brewor just ./configure && makefrom a Node.js' tarball.

你可以安装它从安装程序brew或者只是./configure && make从一个Node.js的压缩包。

There's also Rhino.

还有犀牛

回答by pbfy0

v8. Its the javascript engine used in google chrome. You have to compile it for mac OS X, though. Theres a good tutorial here.

v8. 它是 google chrome 中使用的 javascript 引擎。不过,您必须为 mac OS X 编译它。这里有一个很好的教程。

回答by CuriousMind

You have two options:

您有两个选择:

  1. Use console in your Browser: Browsers such as chrome,safari, firefox come buildtin with console which are cappable of running javascript. to open open console on chrome. Press CTRL+ SHIFT+ J

  2. Install Nodejs: As others have pointed out, try http://nodejs.org/using which you can run javascript in terminal app similar to irb

  1. 在浏览器中使用控制台:chrome、safari、firefox 等浏览器自带控制台,可以运行 javascript。在 chrome 上打开打开的控制台。按CTRL+ SHIFT+ J

  2. 安装 Nodejs:正如其他人所指出的,尝试使用http://nodejs.org/可以在类似于 irb 的终端应用程序中运行 javascript