Chromeコンソールでjavascriptをデバッグするときに、関数のローカル変数を変更する必要があります。グローバル変数の値を変更する方法はわかっていますが、Chromeコンソールでデバッグするときにローカル変数の値を変更するにはどうすればよいですか。Chromeコンソールでデバッグするときにjsローカル変数の値を変更する方法
1
A
答えて
3
Chromeコンソールでをデバッグしていません。あなたはをChromeデバッガでデバッグします。また、デバッガのブレークポイントで停止した場合は、コンソールを使用してスコープ内変数の値を割り当てて変更することができます。
例えば、オープンのdevのツールとのコメントを読んで、このコードを実行:あなたは別のローカル変数の値を再定義したいと思う場所
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();
2
を助けるかもしれません。 – footoss
2回目は、あなたがそのスコープにいるときに必要なだけ多くのconsole.logステートメントを書くことができるということです。それでも13が表示されます。コードをもう一度実行しているときにもう一度13としてログに記録する場合は、変数を13に再設定してください – pshirishreddy