ES5 riddle -- this binding in accessors accessed as global vars

Allen Wirfs-Brock allen at
Mon May 2 17:50:13 PDT 2011

According to the spec. it should alert the global object:
The reference to foo resolves to a Reference to an object environment record.  When getValue is called on  that reference it goes through step 5.a and calls GetBindingValue on the env record.  GetBindingValue does a [[Get]] on the global object.  [[Get]] internally retrieves an accessor property and does a call to the [[Get]] function passing the global objet as the this value.


On May 2, 2011, at 4:43 PM, Mark S. Miller wrote:

> According to the ES5 spec, should the following program alert the global object or undefined? Why?
>     Object.defineProperty(this, 'foo', {get:function(){"use strict"; return this;}});
>     alert((function(){"use strict"; return foo;})());
> -- 
>     Cheers,
>     --MarkM
> _______________________________________________
> es5-discuss mailing list
> es5-discuss at

More information about the es-discuss mailing list