console.log javascript [功能] [英] console.log javascript [Function]

查看:130
本文介绍了console.log javascript [功能]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to log a function in javascript:

console.log(callback)
>>[Function]

我想看看函数是什么。我可以这样做吗?

I want to see what the function is. Can I do that? Thanks.

推荐答案

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

If it's a user defined function you can use:

console.log(callback.toString());

否则你会得到 [native code] 因为内置函数不是用JavaScript编写的。

Otherwise you'll just get something like [native code] since built in functions are not written in JavaScript.

例如:

function x(){}

// Prints "function x(){}"
(function(callback){ console.log(callback.toString()); })(x);

这篇关于console.log javascript [功能]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆