I am trying to print an object to the console to see the values using console.log()
. I see that functions are printed this way.
variable1:
title:
"hello world!!!"
variable2:
callback: ƒ callback()
length: 0
name: "callback"
prototype:
constructor: ƒ callback()
[[Prototype]]: Object
arguments: (...)
caller: (...)
[[FunctionLocation]]: functions_mapper.ts:10
Is there any way to get the exact function definition instead of the location? My use case is not just to output and see but to download it in a file. How can I do this? Thanks!!!
PS: Doing variable2.callback.toString() gives the function definition, but the object has different types of variables in a nested fashion. And we aren't aware of them. When doing copy(object)
from the console is giving variable2: {}
. How to make it store the function definition? Do we have to go to each nested variable, check if it is a function, and call the toString() method?