Breakpoint on anonymous function passed in as argument

976 views
Skip to first unread message

scott....@sap.com

unread,
Jun 1, 2012, 4:30:21 PM6/1/12
to google-chrome-...@googlegroups.com
Hi,

Is it possible to configure a breakpoint so that it can disambiguate between invocation contexts?  For example, if I am passing an anonymous function as an argument to another function:

f(function() { /* do something */ });

Is it possible to set a breakpoint such that it will break when my anonymous function is invoked instead of when the call to f() is made?  Even breaking in both cases would be acceptable.

Currently the only way I know of to do this is to change the code so that it falls across multiple lines like this:

f(function() {
    /*do something*/
});

Is there accomplish this with a code change?

Thanks,
scott 
 
 
 

scott....@sap.com

unread,
Jun 1, 2012, 4:33:42 PM6/1/12
to google-chrome-...@googlegroups.com
Is there accomplish this with a code change? 

That should read "Is there a way to accomplish this without a code change"... :P

PhistucK

unread,
Jun 1, 2012, 4:36:55 PM6/1/12
to scott....@sap.com, google-chrome-...@googlegroups.com
Are you aware of the pretty print feature?
It may help in this case, because it will probably make the anonymous function span over multiple lines.
The other option is to add the "debugger;" statement (either in the actual source code, or in edit mode within the Developer Tools on the fly).
f(function() { debugger; /* do something */ });

PhistucK

scott....@sap.com

unread,
Jun 1, 2012, 4:46:35 PM6/1/12
to google-chrome-...@googlegroups.com, scott....@sap.com
On Friday, June 1, 2012 1:36:55 PM UTC-7, PhistucK wrote:
Are you aware of the pretty print feature?
It may help in this case, because it will probably make the anonymous function span over multiple lines.
The other option is to add the "debugger;" statement (either in the actual source code, or in edit mode within the Developer Tools on the fly).
f(function() { debugger; /* do something */ });

I was sort of aware of the pretty print feature but don't often use it so I didn't realize that it broke out functions like this.  And the "debugger" statement worked well, too.  So between those options I can definitely do what I want.  Thanks so much! 
Reply all
Reply to author
Forward
0 new messages