Warning: This question was about a pre-2016 version of Google Chrome. As of version 126, Chromium's behavior has improved much. The screenshot below does not represent current behavior (and the solution has become obvious).
When I print an object in Chrome's console (for example using log()
), I see all its properties, including methods, but I can't see the definition (contents) of each method. How can I view the definition (code) of an object's method?
I've created a fiddle that may help explain what I'm looking for. Here is a screenshot of that fiddle:
f (e)
and click with your pointing device's secondary button (aka right-click)The function definition is now displayed in the Sources tab.
Alternatively, log the result of
Function.prototype.toString.call(someObj.methodOne)
/*
function (e) {
return 'e is ' + e;
}
*/
A third choice is to double click on f (e)
, which expands the function in an edit box. I personally don't like this method because it's misleading - you can't actually make changes but typing does change the contents of the box and any other logging activity will cause you to lose focus.