var fun1=function(){console.log('hello');}
var fun2=fun1
console.log(fun2);
The above code run in Firefox prints fun2
. In Chrome it prints the function body, in Node.js it prints Function
.
Why is this difference?
How can I get Firefox's behaviour in Node.js ?
Why I am asking this ?
I am asking this because I would like to debug JS code generated from Idris where the JS runtime uses explicit call stack, and I would like to print the callstack content in a meaningful way and Firefox does that the best but I want to debug code on Node.js hence I would like to get Node.js to print functions as Firefox, how can I do that ?
EDIT:
A typical compiled function looks like this:
var _idris__123_io_95_bind2_125_ = function(oldbase){
var myoldbase = new i$POINTER();
i$valstack_top += 1;
i$ret = new i$CON(65646,[i$valstack[i$valstack_base],i$valstack[i$valstack_base + 1],i$valstack[i$valstack_base + 2],i$valstack[i$valstack_base + 3],i$valstack[i$valstack_base + 4],i$valstack[i$valstack_base + 5]],_idris__123_APPLY0_125_$65646,null);
i$valstack_top = i$valstack_base;
i$valstack_base = oldbase.addr;
}
So here the useful information is the variable name _idris__123_io_95_bind2_125_
itself, and that is what is printed by Firefox
, but not by node.js
, and that is the problem, Firfox prints useful information, node.js
does not.
So the question is, how can I make node.js
to print _idris__123_io_95_bind2_125_
for the above function ?
EDIT 2:
Trying some of the suggestions don't work unfortunately :
>cat deb.js
var fun1=function(){console.log('hello');}
var fun2=fun1
console.log(fun2);
console.log(fun2.name);
console.log(fun2.toString());
console.log(fun2+'');
>node deb.js
[Function]
function (){console.log('hello');}
function (){console.log('hello');}
>