Prototype chain for objects that implement multiple interfaces

Hi everyone.

What should the prototype chain for an object that implements multiple
interfaces looks like?  A single interface is simple enough:

  NodeList = { an object }
  NodeList.[[Prototype]] = Object prototype object
  NodeList.prototype = { an object }
  NodeList.prototype.[[Prototype]] = Object prototype object
  NodeList.prototype.constructor = NodeList
  NodeList.prototype.someFunction = { some function }

  nl = { an object }
  nl.[[Prototype]] = NodeList.prototype

What happens if an object implements multiple interfaces, e.g. an
Element that is also an EventTarget?  I can imagine a way to handle this
with prototypes, for example:

  Node = { an object }
  Node.[[Prototype]] = Object prototype object
  Node.prototype = { an object }
  Node.prototype.constructor = Node

  Element = { an object }
  Element.[[Prototype]] = Object prototype object
  Element.prototype = { an object }
  Element.prototype.[[Prototype]] = Node.prototype
  Element.prototype.constructor = Element

  EventTarget = { an object }
  EventTarget.[[Prototype]] = Object prototype object
  EventTarget.prototype = { an object }
  EventTarget.prototype.constructor = EventTarget

  elt = { an object }
  elt.[[Prototype]] = { an object }
  elt.[[Prototype]].[[Prototype]] = null
  elt.[[Prototype]].[[Get]](P):
      1. If O doesn’t have a property with name P, go to step 4.
      2. Get the value of the property.
      3. Return Result(2).
      4. Call the [[HasProperty]] method of the Element prototype
         object.
      5. If Result(4) is true, go to step 9.
      6. Call the [[HasProperty]] method of the EventTarget prototype
         object.
      7. If Result(6) is true, go to step 11.
      8. Return undefined.
      9. Call the [[Get]] method of the Element prototype object.
      10. Return Result(9).
      11. Call the [[Get]] method if the EventTarget prototype object.
      12. Return Result(11).

The same question could apply to multiple inheritance (which is allowed
by OMG IDL, but AFAIK is not used in any of the DOM specs).

This is probably not what browsers do in practice, though.  For example,
Opera 9 has an addEventListener method directly on the Node interface
prototype object (see http://mcc.id.au/2007/05/binding-tests/#t008),
presumably because all Node objects in a document also implement
EventTarget.

Any opinions on how to specify this?

Thanks,

Cameron

-- 
Cameron McCormack, http://mcc.id.au/
 xmpp:heycam@jabber.org  ▪  ICQ 26955922  ▪  MSN cam@mcc.id.au

Received on Wednesday, 6 June 2007 04:36:58 UTC