I have a function like so:
const ILog = <T>(value: T): T => {
console.log(value);
return value;
}
It acts like console.log
with the added benefit that it keeps the value it had.
However, I'd like to differenciate between calls of the same function:
let a = false;
let b = false;
let c = false;
ILog(a);
ILog(b);
ILog(c);
// current
$ node file.js
false
false
false
// expected
$ node file.js
ILog(a): false
ILog(b): false
ILog(c): false
Can some javascript black magic achieve this?
An example of how this would work would be like this:
const ILog = (name: string) => <T>(value: T): T => {
console.log(`ILog(${name})`, value);
return value;
}
ILog("[some_expression]")([some_expression]);
$ node file.js
ILog([some_expression]): [result]
Without repeating the expression in string form.