View Javascript Method Content in Chrome Console

When I console.log an object in Chrome, I see all the properties and the name of the method, but I do not see the contents of the method itself. How to view the contents of an object method?

I created a JSFiddle that can help explain what I'm looking for.

How to view a Javascript method's contents console

+5
source share
2 answers
  • Find the function of interest in the console
  • Right-click the word function
  • Click Show Feature Definition
  • The function is now displayed on the Sources tab.

Alternatively, write down the result

 Function.prototype.toString.call(someObj.methodOne) /* function (e) { return 'e is ' + e; } */ 

The third option is to double-click on the word function , which extends the function in the editing window, but I personally do not like this method because it is misleading - you can’t actually make changes, but the keys you enter change the contents of the field and any other registration activities will result in loss of focus.

+5
source

Remember that function is just syntactic sugar for the function object. Because of this, Object toString() inherited.

So, to answer your question:

console.log(someObj.methodOne.toString()) .

+3
source

All Articles