console.log javascript [功能]

Har*_*rry 87 javascript console function node.js

我正在尝试在javascript中记录一个函数:

console.log(callback)
>>[Function]
Run Code Online (Sandbox Code Playgroud)

我想看看这个功能是什么.我能这样做吗?谢谢.

Pau*_*aul 128

如果它是用户定义的函数,您可以使用:

console.log(callback.toString());
Run Code Online (Sandbox Code Playgroud)

否则你会得到一些东西,[native code]因为内置的函数不是用JavaScript编写的.

例:

function x(){}

// Prints "function x(){}"
(function(callback){ console.log(callback.toString()); })(x);
Run Code Online (Sandbox Code Playgroud)

  • 不,因为问题用node.js标记,表明根本没有窗口,并且始终可以预期console.log.http://nodejs.org/api/stdio.html (11认同)
  • @foiseworth链接死了 (2认同)