I can use get for individual properties, like this:
function MyObjectConstructor() {
this._internalValueOne = 'foo';
this._internalValueTwo = 'bar';
}
MyObjectConstructor.prototype = {
get usefulValueOne() {
return this._internalValueOne + 'baz';
},
get usefulValueTwo() {
return this._internalValueTwo + 'baz';
}
}
var myObject = new MyObjectConstructor();
Now myObject.usefulValueOne gives 'foobaz' and myObject.usefulValueTwo gives 'barbaz'. Can I somehow use get to make sure that myObject (and any other object based on MyObjectConstructor) also returns an object like {usefulValueOne: 'foobaz', usefulValueTwo: 'barbaz'}? Or is there some other preferred way to do this?
Naturally I also wonder the same thing for set.
you can use this:
now myObject.showProp will show you an object with all properties (including privates, you should remove them)