I have implemented this immutable Pos object:
var Pos = function(x, y) {
var _x = x;
var _y = y;
return {
x: function() { return _x; },
y: function() { return _y; },
};
}
Now when I write new Pos(5, 7) to the console, it is displayed like this:
▶ Object {x: function, y: function} // Chrome
Object { x: Pos/<.x(), y: Pos/<.y() } // Firefox
That is not useful at all, as I cannot see the values for x and y.
I could make a custom function to log x and y, but that would really not be as good, and I would lose the useful possibility to expand the object and navigate inside (imagine more complex objects, Pos is just one example).
If it was in C#, I would just override ToString(), and then Visual Studio would automatically use it in the debugger to display my object.
In JS however implementing toString doesn't seem to help at all. Is there any way to see my object's x and y easily in the console?
get x() { return _x; },otherwise, there's no link to the private var w/o executing the method, which the console won't do for obvious reasons.