我如何运行一些JavaScript代码段

As I learn and try new different things using Javascript, I run little snippets of JavaScript every day.

当我学习和尝试使用Javascript进行新的尝试时,我每天都会运行一些JavaScript代码段。

Sometimes I just open a Chrome or Firefox DevTools window and type things there. This is perfect to try out a line or two, but it can quickly become a little of a problem if you have to spend some time on the code. For example, if you declare a const value, you need to refresh the window to re-run it.

有时,我只是打开Chrome或Firefox DevTools窗口并在其中键入内容。 尝试一两行是完美的选择,但是如果您不得不花一些时间在代码上,那么很快就会成为一个小问题。 例如,如果声明一个const值,则需要刷新窗口以重新运行它。

There is a nice VS Code extension called Quokka.js. It’s a great way to test JS snippets while working in your editor.

有一个很好的VS Code扩展名为Quokka.js 。 这是在编辑器中工作时测试JS代码片段的好方法。

Another tool I use is RunJS, a little Electron application.

我使用的另一个工具是RunJS ,这是一个小小的电子应用程序。

我如何运行一些JavaScript代码段

You can type code on the left, and the app shows the result on the right.

您可以在左侧输入代码,然后该应用在右侧显示结果。

The code evaluates as you type, so you don’t have to press “run” or have roadblocks while you try things out.

该代码会在您键入时进行评估,因此您在尝试操作时不必按下“运行”或设置障碍。

It can test both browser and Node.js code.

它可以测试浏览器 Node.js代码。

You can import Node modules just by setting a working directory where it can find them in a node_modules folder. Or you can just install npm packages from the “Action -> Install NPM packages” menu.

您可以仅通过设置工作目录来导入Node模块,该目录可以在node_modules文件夹中找到它们。 或者,您可以仅从“操作->安装NPM软件包”菜单中安装npm软件包。

It supports TypeScript and Babel.

它支持TypeScript和Babel。

It’s currently macOS-only, but I’m sure there are similar tools for Linux and Windows.

它目前仅适用于macOS,但我确定对于Linux和Windows也有类似的工具。

翻译自: https://flaviocopes.com/run-javascript-snippets/