Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
186
rated 0 times [  188] [ 2]  / answers: 1 / hits: 151562  / 14 Years ago, wed, january 5, 2011, 12:00:00

I'm debugging a javascript app (using Chrome dev tools), and I would like to change some variable values while stepping through the code.



Is that possible at all?



I have tried and got something like:



> modeline
1
> modeline=0
0 <<< seems to work but...
> modeline
1 <<< ups!!


But I'm unable to find any documentation that states what can or can't be done...


More From » debugging

 Answers
9

Why is this answer still getting upvotes?



Per Mikaël Mayer's answer, this is no longer a problem, and my answer is obsolete (go() now returns 30 after mucking with the console). This was fixed in July 2013, according to the bug report linked above in gabrielmaldi's comment. It alarms me that I'm still getting upvotes - makes me think the upvoter doesn't understand either the question or my answer.



I'll leave my original answer here for historical reasons, but go upvote Mikaël's answer instead.






The trick is that you can't change a local variable directly, but you can modify the properties of an object. You can also modify the value of a global variable:



var g_n = 0;
function go()
{
var n = 0;
var o = { n: 0 };
return g_n + n + o.n; // breakpoint here
}


console:



> g_n = 10
10
> g_n
10
> n = 10
10
> n
0
> o.n = 10
10
> o.n
10


Check the result of go() after setting the breakpoint and running those calls in the console, and you'll find that the result is 20, rather than 0 (but sadly, not 30).


[#94370] Monday, January 3, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
isham

Total Points: 69
Total Questions: 86
Total Answers: 86

Location: Anguilla
Member since Sun, Jan 29, 2023
1 Year ago
;