Reputation: 11585
Say I want to look at an object and so I log it to the console:
console.log(theNoticeObj);
Then using Chrome Dev Tools, I inspect it in the console and change its property theNoticeObj.bounceHeight to 10px
Now if I want to trigger theNoticeObj.bounce() on that object immediately to locate it, is there an easy way to do that from the console?
Thanks
EDIT:
Breakpoints where suggested below, but this freezes execution.
In face what I want is the command line API to work with javascript objects, not just DOM elements. If that were possible I'm sure I would be able to find it. I might go and see if there are any feature requests to that end for chrome. https://developers.google.com/chrome-developer-tools/docs/console#using_the_command_line_api
Upvotes: 4
Views: 4281
Reputation: 8116
Now you can right click any object in the console and use "Store as global variable".
A new console line appears with the name of a new global variable holding reference to the selected object.
Upvotes: 0
Reputation: 1585
You can navigate to the Sources
tab and open your javascript file containing the piece of code you want to play with, in this case let us assume it is
console.log(theNoticeObj);
Once you find this line, you can set a breakpoint at this point and when your program execution comes to this line it will halt.
You can then use the Console
tab to do operations on all the javascript objects in current local scope, window scope. You can simply call:
theNoticeObj.bounce();
It executes in the current context reflecting changes on the screen.
Hope this helps.
Upvotes: 1
Reputation: 1755
Try adding window.tno = theNoticeObject
under the console.log statement. Reload the page and see if you can execute tno.bounce()
from the console. If theNoticeObject is still in scope, this should work.
Upvotes: 3