I want to dump this array to string and get the same object after evaluating it.
arr = [5, 86, function() { console.log(arguments); }, [console.log, 357]];
Although, functions may have extra properties, only the code is necessary to reproduce.
I can't find a way to do this in Node:
> console.log(arr)
[5, 86, [Function] [ [Function], 357] ]
> util.format('%j', arr)
'[5,86,null,[null,357]]'
> arr.toString()
'5,86,function () { console.log(arguments); },function () {\n process.stdout.write(util.format.apply(this, arguments) + \'\\n\');\n},357'
The latter has flatterned the array.
Is there a better way?
update: found the satisfying solution, see my own answer.