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

Cameron McCormack cam at mcc.id.au
Fri Nov 25 19:19:16 PST 2011


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?


More information about the whatwg mailing list