简体   繁体   English

在 VS 代码中运行隔离的 JavaScript 命令(不是当前文件)

[英]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.

相关问题 在“孤立的世界”(chrome)中运行javascript - Run javascript in an “isolated world” (chrome) 在 VS Code 中调试当前文件 - Debugging current file in VS Code VS 代码没有将关键字“this”链接到当前的 javascript object? - VS Code not linking keyword “this” to current javascript object? 无法在 VS 代码中运行 javascript 代码 - Not able to run the javascript code in VS code VS Code 如何为每个单独的 Js 文件配置具有隔离类型系统的项目 - VS Code how to configure a project with isolated type system per individual Js file 无法在 VS Code 中调试当前 typescript 文件,因为找不到对应的 JavaScript - Can't debug current typescript file in VS Code because corresponding JavaScript cannot be found 如何在 VS 代码中运行 html & javascript - How to run html & javascript in VS Code 什么是运行 python 文件的 VS 代码命令? - What is a VS Code Command to run a python file? 读取与当前文件位于同一目录中的另一个文件(VS代码) - Reading another file in the same directory as the current file (VS Code) Javascript 代码未显示所需的 output 如果运行 vs 代码 - Javascript Code not showing desired output if run through vs code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM