var MyObj = function(x) {
this.x = x;
this.y = 5;
};
MyObj.prototype.example = function() {
// I want to return a new object which has access to this.x and this.y
// For example:
return {
addTwo: function() {
// How can I access this.x from the MyObj instance?
return 2 + (x from the instance of MyObj)
}
}
};
How can I return an object from the example method so that it has access to the instance variables from an instance of MyObj?
I can't use 'this' inside the returning object, or else it will refer to the object that I am returning.
And I am not using es6