admin管理员组文章数量:1332395
When I debug javascript with the Chrome console, I want to change a local variable of a function. I know how to change the value of global variables, but how do I change the value of a local variable when debugging in the Chrome console?
When I debug javascript with the Chrome console, I want to change a local variable of a function. I know how to change the value of global variables, but how do I change the value of a local variable when debugging in the Chrome console?
Share Improve this question edited Jun 12, 2016 at 10:17 Peter Brittain 13.6k3 gold badges44 silver badges59 bronze badges asked Jun 12, 2016 at 10:06 footossfootoss 631 silver badge7 bronze badges2 Answers
Reset to default 4You don't debug in the Chrome console. You do debug in the Chrome debugger. And if you are stopped at a breakpoint in the debugger, you can use the console to change the value of any in-scope variable by assigning to it.
For instance, open dev tools and run this code, reading the ments:
function foo() {
var bar = 42;
// Normally, you don't have to use a hardcoded breakpoint like
// the one that follows, you can set a breakpoint from within the
// debugger just by navigating to the line of code and clicking in
// the left-hand gutter. But in Stack Snippets the easiest way to
// do one is to use the debugger statement:
debugger;
// Now, when stopped on the breakpoint, type this in the console:
// bar = 67;
// ...and press Enter.
// Then hit the arrow button to allow the script to continue
console.log(bar); // ...and this will log 67 instead of 42.
}
foo();
Try setting a break point where you would want to redefine the local variable's value to a different one. Then you get access to all the data in that scope.
This might help
本文标签: javascriptHow to change the value of js local variable when debug in Chrome consoleStack Overflow
版权声明:本文标题:javascript - How to change the value of js local variable when debug in Chrome console - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742282745a2446395.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论