Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
193 views
in Technique[技术] by (71.8m points)

console.log javascript [Function]

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

console.log(callback.toString());

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

Example:

function x(){}

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...