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

[whatwg] API design restrictions due to barewords in onxxx="" attributes

From: Cameron McCormack <cam@mcc.id.au>
Date: Sat, 26 Nov 2011 14:19:16 +1100
Message-ID: <4ED05AB4.7050009@mcc.id.au>
This problem of using bare variables names rather than 
window.variableName in event handler attributes (which Boris mentions in 
https://developer.mozilla.org/Writing_Forward_Compatible_Websites) seems 
annoying.  Is there any way we can avoid it by codifying current 
property lookup behaviour for all existing properties on 
elements/Document/Window while allowing newly introduced properties not 
to be found when using bare identifiers?

I think we could have an object on the scope chain (when onxxx=""s are 
run) that will, instead of having names resolved in this order:

   1. look on element
   2. look on element's form (if it has one)
   3. look on document
   4. look on window

(which I assume is achieved by simply having those four objects on the 
scope chain in that order) does this instead:

   1. if property name is in set S, then:
        a. look on element
        b. look on element's form (if it has one)
        c. look on document
      otherwise:
        a. look at element's named properties (if it has any)
        b. look at element's form's named properties (if it has a form)
   2. look on window

where S is the set of property names corresponding to

   * the IDL attributes, operations and constants on element's
     interface,
   * those on HTMLFormElement (if the element has a form), and
   * those on Document

for the current set of APIs we have deployed.

Would this work?  Does it sound too brittle or hacky?
Received on Friday, 25 November 2011 19:19:16 UTC

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:09:09 UTC