How to Print Function Signature in javascript

后端 未结 3 1943
再見小時候
再見小時候 2021-02-02 10:08

I have a function:

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

Sometime later I want to see the signature of th

3条回答
  •  有刺的猬
    2021-02-02 10:27

    In node.js specifically, you have to convert the function to string before logging:

    $ 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+""

提交回复
热议问题