How can I debug a variable of type [Function]?
Some functions are defined in variables. And I want to debug what function is installed there? However, this function cannot be changed. In this situation, how should I debug?
var something = returnfunc(); //returnfunc() return function type object
console.log(something);
[Function]
+3
Harry
source
to share
3 answers
You can call toString
in a function to get a string representation of the source code;)
eg:.
let fn = (a, b) => a + b;
console.log(fn.toString())
// (a, b) => a + b
+2
Luan nico
source
to share
Perhaps you meant the type of object validation that has a function value:
var something = returnfunc;
console.log(typeof something);
0
Ilya Zinkevych
source
to share
I think you are asking how to define the function to return returnfunc
. If you are using an anonymous function, it is harder to debug because the function is not identified by 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]
0
djfdev
source
to share