Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

node怎么打印完整的函数?

$
0
0

node打印对象的方法有console, util.inspect, JSON.stringify,而且可以完整的打印;

JSON.stringify(obj, null, 1);  //JSON.stringify(value[, replacer[, space]])

第二参数用null,不用替换,第三个参数格式打印缩进或替代缩进的方式

但是,有没有可以完整打印函数的方法?比如很简单一个函数:

let a = function () {
    let b = 1;
    let c = 0;
    return b + c;
}

我想完整打印出来里面,显示代码

用console.log() 或者util.inspect()打印: [Function: a] 用JSON.stringif()打印是 undefined


Viewing all articles
Browse latest Browse all 14821

Trending Articles