Trying to do this:
var c = {
x: \'other context\'
};
var o = {
x: \'this context\',
get otherContext () {
alert(this.x);
}.bind(c)
};
o.otherCon
The problem is that method syntax doesn't use function expressions. It's a defined syntactic structure.
MethodDefinition[Yield] :
PropertyName[?Yield] ( StrictFormalParameters ) { FunctionBody }
GeneratorMethod[?Yield]
get PropertyName[?Yield] ( ) { FunctionBody }
set PropertyName[?Yield] ( PropertySetParameterList ) { FunctionBody }
PropertySetParameterList :
FormalParameter
Since it isn't a function expression, you don't have access to the functions methods or properties.
You can accomplish what you want with Object.defineProperty.
var proxy = { ... };
Object.defineProperty(proxy, 'left', {
get: function() {
return this.el.offsetLeft;
}.bind(this)
});