Say for example, I have the following Javascript,
var User=Backbone.Model.extend({
});
var jt=new User({name:"jonathan"});
How would I access jt in the Chrome console?
>jt // doesn't work
>Backbone.... ?
thx
you have to make the jt
variable global:
jt = new User({name:"jonathan"});
or
window.jt = new User({name:"jonathan"});
or just use the console while in the debugger and set a breakpoint on that line
Peter's answer will do the trick, but it is generally considered bad practice to start making things global. If it's just a quick thing that you plan on reverting, it's ok, but you have to be careful to remember to fix it.
Since you're using Chrome, you can make use of the powerful debugger. Just add a line with debugger
right after you've set something you want to inspect.
var User=Backbone.Model.extend({
});
var jt=new User({name:"jonathan"});
debugger;
If you have the developer tools open, refreshing the page will basically set a break point at the debugger. You can then hit Esc
to open up a console at the exact scope at which you put your debugger line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With