Given the following piece of code:
function Constructor(){}
var proto = Constructor.prototype;
proto.someMethod = function(){};
proto.someProperty = "some value";
proto.obj = {};
Object.defineProperty(proto.obj, "prop", {
get: function() {
return this.someMethod() + this.someValue;
}
});
var instance = new Constructor();
instance.obj.prop; // => Uncaught TypeError: undefined is not a function
A function used as getter or setter has its 'this' value bound to the object from which the property is being set or gotten. The 'this' value of the getter function in the code points to 'proto.obj'. Is there a way of binding the getter function's 'this' value to instances of 'Constructor' in order to be able to access properties and methods?