I want to do this: log(variableOrFunction)
And be able to produce this: variableOrFunction: actualValue
.
I tried this:
Would this work for you?
const log = function() {
const key = Object.keys(this)[0];
const value = this[key];
console.log(`${key}:${value}`);
}
let someValue = 2;
log.call({someVlaue}); //someValue:2
Works with function too, even itself.
log.call({log});
// It would return the following
log:function() {
const key = Object.keys(this)[0];
const value = this[key];
console.log(`${key}:${value}`);
}