Why are global variables *non-deletable* properties of the global object?
Maciej Stachowiak
mjs at apple.com
Fri Jun 20 11:46:44 PDT 2008
On Jun 19, 2008, at 11:20 PM, Brendan Eich wrote:
> On Jun 19, 2008, at 8:40 PM, Mark S. Miller wrote:
>
>>> Try putting this in a Firefox address toolbar:
>>>
>>> javascript:alert('foo' in window); var foo = 42; alert(delete foo);
>>> alert(foo)
>>>
>>> You will get true (because the var binding -- not initialization
>>> -- is
>>> hoisted to the top of the program, right after the javascript:),
>>> false
>>> (because var makes a DontDelete binding outside of eval), and 42.
>>
>> I did. Thanks for suggesting that experiment. But given the above
>> behavior, I don't understand
>>
>> javascript:alert('foo' in window); var foo = 42; window.foo = 43;
>> alert(delete window.foo); alert(window.foo)
>>
>> I get true, true, undefined.
>
> Works correctly (true, false, 43) in Firefox 3 (try it, you'll like
> it!).
Also works correctly in Safari 3.1 and the Safari 4 Developer Preview
(which implements split window support).
Regards,
Maciej
More information about the Es4-discuss
mailing list