[英]Run isolated JavaScript commands in VS Code (not current file)
I am looking for a way to run individual commands in VS Code but not the whole file.我正在寻找一种在 VS Code 中运行单个命令而不是整个文件的方法。 I do work on client websites where a lot of my code will not run in a standard debugger or in the Quokka extension because it relies on the page that I am working on (and running in the debugger does not perfectly emulate how my code will run. But sometimes I like to run a few lines of code or a single function separately to make sure I have it set right without having to copy my code over to the online platform used to execute it and load up a preview link. Normally what I like to do is open a new chrome tab at
about:blank
and use the dev console there to paste in my code and this is my "playground" of sorts. Is there any form of active JS engine that I can do this in without having to save these lines to a new file and run the debugger?我确实在客户端网站上工作,我的很多代码不会在标准调试器或 Quokka 扩展中运行,因为它依赖于我正在处理的页面(并且在调试器中运行并不能完美地模拟我的代码将如何运行. 但有时我喜欢单独运行几行代码或单个 function 以确保我设置正确,而无需将我的代码复制到用于执行它的在线平台并加载预览链接。通常我喜欢做的是在
about:blank
打开一个新的 chrome 选项卡并使用那里的开发控制台粘贴我的代码,这是我的“游乐场”。有没有任何形式的活动 JS 引擎我可以在没有的情况下做到这一点将这些行保存到新文件并运行调试器?
If you looking all these things in VS code I think it will be a bit hard because of this.如果你在 VS 代码中查看所有这些东西,我认为这会有点困难。
to run JS code snippet VS code must have JS engine like same for PHP its compiler or same for any other language and adding these compilers in IED will again make these IEDs fat and CPU costly.要运行 JS 代码片段 VS 代码必须具有与 PHP 相同的 JS 引擎,它的编译器或任何其他语言的相同,并且在 IED 中添加这些编译器将再次使这些 IED 变得肥胖且 CPU 成本高。
BUT Still, you can do one thing if you have a node js installed open Terminal outside or inside the VS code.但是,如果您在 VS 代码外部或内部安装了节点 js 打开终端,您仍然可以做一件事。
and type并输入
$node
This will open a JS playground.这将打开一个 JS 操场。 Where you can execute js code snippets
哪里可以执行js代码片段
but here you will not be able to access DOM, WINDOW object, etc.但是在这里你将无法访问 DOM、WINDOW object 等。
In case you found any plugin which executes js code in VS CODE with DOM, window please let me know.如果您发现任何在 VS CODE 中使用 DOM 执行 js 代码的插件,请告诉我 window。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.