How to print the Signature function in javascript

I have a function:

fs.readFile = function(filename, callback) { // implementation code. }; 

After some time, I want to see the signature of the function during debugging.

When I tried console.log(fs.readFile) , I got [ FUNCTION ] .

It does not give me any information.

How can I get a function signature?

+8
javascript debugging
source share
3 answers

In node.js, you need to convert the function to a string before writing:

 $ node > foo = function(bar, baz) { /* codez */ } [Function] > console.log(foo) [Function] undefined > console.log(foo.toString()) function (bar, baz) { /* codez */ } undefined > 

or use a shortcut like foo+""

+17
source share

I'm not sure what you want, but try looking at the console log of this violin, it will print out the full definition of the function. I am looking at the output of chrome console.log.

 var fs = fs || {}; fs.readFile = function(filename, callback) { alert(1); }; console.log(fs.readFile); 

DEMO http://jsfiddle.net/K7DMA/

+2
source share

If you mean by "function signature" how many arguments it defined, you can use:

 function fn (one) {} console.log(fn.length); // 1 

All functions automatically get the length property.

+1
source share

All Articles