Reputation: 1347
Some functions are set into variables. And I want to debug what kind of function is set there? However that function can non be changed. In this situation, how should I debug?
var something = returnfunc(); //returnfunc() return function type object
console.log(something);
[Function]
Upvotes: 3
Views: 317
Reputation: 6037
I think you're asking how to identify the function returned by returnfunc
. If you use an anonymous function, it is harder to debug because that function is not identified with a name:
function returnfunc () {
return function () {
return 'I am an anonymous function'
}
}
var fn = returnfunc() // [Function]
But you can just give the function a name:
function returnfunc () {
return function foo () {
return 'I am a named function'
}
}
var fn = returnfunc() // [Function: foo]
Upvotes: 0
Reputation: 51
Maybe you meant check type of object that has value of function:
var something = returnfunc;
console.log(typeof something);
Upvotes: 0
Reputation: 5917
You can call toString
in the function to get a string representation of the source code ;)
E.g.:
let fn = (a, b) => a + b;
console.log(fn.toString())
// (a, b) => a + b
Upvotes: 2