[英]How do I debug Javascript Function in vscode?
Macbook, OSX 10.9 VsCode - Enterprise 2019 Macbook、OSX 10.9 VsCode - 企业版 2019
// Issue Description // 问题描述
I have a very simple JS function我有一个非常简单的 JS function
function countup(n) {
if (n < 1) {
return [];
} else {
const countArray = countup(n - 1);
//debugger;
countArray.push(n);
return countArray;
}
}
console.log(countup(5));
What I need help with?我需要什么帮助?
Run this with a debugger on vscode by adding breakpoints in between.通过在两者之间添加断点,在 vscode 上使用调试器运行它。 When I try to use the launch.json config
当我尝试使用 launch.json 配置
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome",
"file": "${workspaceRoot}/Test.js"
}
]
}
This basically renders the JS file in Chrome but does not execute the actual function.这基本上在 Chrome 中呈现 JS 文件,但不执行实际的 function。 I have tried the same with a local server + chrome debugger extension in vs code.
我在 vs 代码中使用本地服务器 + chrome 调试器扩展进行了同样的尝试。
How do I get this to work?我怎样才能让它工作?
to run the JS code, you need to open a new HTML file and run the code in the HTML.要运行 JS 代码,需要打开一个新的 HTML 文件并运行 HTML 中的代码。 if it is just a basic code you can use the Script tag
<script>
and call the function in the body tag using the onload Event.如果它只是一个基本代码,您可以使用 Script 标签
<script>
并使用 onload 事件在 body 标签中调用 function。 after you do that you can use the chrome debugger (press F12)完成后,您可以使用 chrome 调试器(按 F12)
here an example这是一个例子
<body onload="Myfunction()">
<script>
function Myfunction() {
console.log('hello world');
}
</script>
</body>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.