W3C home > Mailing lists > Public > www-dom@w3.org > July to September 2014

Re: Allowing ES6 Symbols as event names

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Mon, 21 Jul 2014 13:01:24 -0400
Message-ID: <53CD4764.2060908@mit.edu>
To: David Bruant <bruant.d@gmail.com>, www-dom@w3.org
On 7/21/14, 12:19 PM, David Bruant wrote:
 >(I assume you mean event.type)

Er, yes.

> For such code to break, it would need to be faced with events which is
> symbole-named. This cannot happen via addEventListener (since it's
> currently impossible to listen to events with a symbol name).

But this is the part you're proposing to change, right?

Think library code that basically calls through to addEventListener but 
also does some stuff with the event before handing it to the library 
consumer.  jQuery's on(), say.

> For such code to break, the code would then need to override the native
> addEventListener and have some code which assumes the event name to be a
> string.

No, it would just need to assume event types are strings.

For what it's worth, jQuery's on() would throw on a symbol-valued type 
right now [1] anyway, so it presumably doesn't have this problem because 
the fail happens much earlier.  But if it didn't fail there, then 
various other parts of jQuery assume you can do regexp matches on 

> This assumption can be true, but in most cases, event names are only
> used for equality

jQuery code begs to differ.  I haven't checked other commonly used 
libraries, but would be moderately surprised if this were true there.

> Above, I started the reasoning with addEventListener, because the DOM
> doesn't have, for instance, a mechanism to listen to all events of a
> given object

Though people do keep asking for it.

And note that some browser extension systems do in fact provide such a 

> So in conclusion, code that would break is overriding
> Event.prototype.addEventListener

I disagree.  It'd just need to interpose in front of addEventListener.

> I briefly looked at jQuery [1] to see if it was using event.type. It
> does only to do === on it or as property key (that's obviously only the
> latest version, I didn't look at other versions, but imagine the story
> is the same).

I looked at jQuery 1.10.2 for what it's worth.  See event.fix for example.

The latest 1.x version of jQuery has the same code.

jQuery 2.1.1 has the same code, actually.  So I'm really not sure which 
"latest version" you looked at.


[1] I believe this will throw on a Symbol:

   types = ( types || "" ).match( core_rnotwhite ) || [""];
Received on Monday, 21 July 2014 17:01:54 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:23 UTC