W3C home > Mailing lists > Public > whatwg@whatwg.org > April 2011

[whatwg] [WHATWG] HTMLElement ids as global object properties

From: Alexandre Morgaut <Alexandre.Morgaut@4d.com>
Date: Sun, 3 Apr 2011 18:53:37 +0200
Message-ID: <BC8A88E4-5B5D-45F5-8427-167A294E2C5D@4d.com>

On 1 avr. 2011, at 14:50, Boris Zbarsky wrote:
>
>> Let's imagine the effects of existing HTMLElements with id like "location", "document", "event", "toolbar", or even "window"...
>
> The id lookup happens after all other property resolution in browsers
> (but NOT in the current spec text, note), so if you had <div
> id="location"> and accessed window.location you would get a Location
> object, not the <div>.

So you can not rely on being able to access an HTMLElement from its id this way...
(As any Javascript code could use a global variable with the same name/id)


>
>> One of the main best practices in JavaScript development is "Don't pollute the global namespace"
>
> Clearly agreed, given the bug report I filed about making this quirks-only.
>
> All you have to do is convince the Trident, Webkit, and Presto teams...
> on the other hand I would love to hear from the latter two what their
> thoughts are.

Is there any registered bug on Opera and Webkit about this topic ?
Or have we got to create one ?


> So far the only feedback I've gotten Microsoft saying
> they will likely run into web compat issues if they make the behavior
> quirks-only.
>
> -Boris





Alexandre Morgaut
Product Manager

4D SAS
60, rue d'Alsace
92110 Clichy
France

Standard : +33 1 40 87 92 00
Email :    Alexandre.Morgaut at 4d.com
Web :      www.4D.com
Received on Sunday, 3 April 2011 09:53:37 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 30 January 2013 18:48:03 GMT