I am trying to customize how an instance is printed in a console.log
statement by default:
function Vehicle(x, y, z) {
this.x = x;
this.y = y;
this.z = z;
this.speed = 0;
this.engineOn = false;
}
Vehicle.prototype.valueOf = function() {
return 'print this';
}
let v = new Vehicle(1,2,3);
console.log(v);
It seems there is a valueOf
and a toString
function, but neither of those seem to change the value. How would I properly change the default format when it's cast to a string in the console.log
statement?