Re: [DOM3 Events] Initialising events (concerns)

Hi, Doug,

--- On Thu, 24/9/09, Doug Schepers <> wrote:

> Sergey Ilinsky wrote (on 9/24/09 6:36 AM):
> > 
> > I am talking about event initialization methods -
> changing
> > initXXXEvent to something different, such as possible
> properties bag
> > passing.
> We aren't adding property-bag passing.  We're
> considering allowing attributes to be writable between the
> time the event is created and when it is dispatched. 
> We would keep the existing initialization methods, for
> back-compat (though we are weighing the costs and benefits
> of not adding new ones for the new interfaces).

CustomEvent should help. It allows to pass a bag of properties.

In the application one could implement a simple convenience function:

function dispatchCustomEvent(oTarget, sType, /* [ */ bCanBubble, bCancelable, oBag /* ] */) {
    var oEvent = oTarget.ownerDocument.createEvent("CustomEvent");
    oEvent.initEvent(sType, !!bCanBubble, !!bCancelable, oBag || null)

dispatchCustomEvent(document.querySelector("#id"), "event");

or a method:

Element.prototype.dispatchCustomEvent(sType, /* [ */ bCanBubble, bCancelable, oBag /* ] */) {
    var oEvent = this.ownerDocument.createEvent("CustomEvent");
    oEvent.initEvent(sType, !!bCanBubble, !!bCancelable, oBag || null)

var o = {my:"my"};
document.querySelector("#id").dispatchCustomEvent("test", true, false, o);

Again, I believe, there are almost no use cases for any events dispatching into DOM apart for unit testing, so maybe an implementation of convenience methods in a certain application framework would suffice.

> A language for which this is a problem would not have to
> allow the attributes to be writable.  It could continue
> to use the initialization methods.
> Is this a problem for Java?

Unfortunately I do not know, got no experience with Java.



Received on Thursday, 24 September 2009 11:32:51 UTC