Re: Marked addEventListenerNS and removeEventListenerNS At Risk

Hi, Jonas!

> There is an important difference.
>
> Elements and attributes use namespaces, but use a prefix mapping
> mechanism so that you won't have to type the full namespace every
> time. Events don't have that.
>
> With Events you'd always be writing:
>
> someEventFunction(..., "http://example.com/myNamespace", "myEvent", ...);
I read this argument before, squeezed between some others in a row. Somehow I didn't attribute much weight to it. Thanks to our getting into this level of detailed discussion now I clearly know why. So it's a good thing :-).
Let me share with you.

You could do var myNs = "http://example.com/myNamespace" and use the myNs variable instead of the namespace name therefrom. This would be the programming equivalent of defining the myNs prefix in markup.

<dreaming-up>
But you've also given me the idea of going further. Creating this variable would be a constant overhead (compared to linear had the namespace name indeed to be fully written at each occurrence) but still about twice as much as ideally needed (and duplication also harms maintainability and other stuff) given the prefix declaration very likely present already in the markup (probably there is markup in most cases you'll want to use this API). So you can call Node.lookupNamespaceURI. You could shorten it using a universal utility function (e.g. function f(node) {return function(prefix) {return node.lookupNamespaceURI(prefix)}}, used thus: f(node)(prefix)). Maybe something like this could make it into an upcoming version of DOM Core. How about Node.ns[prefix]?
</>

Best regards,

Krzysztof
HTML WG

Received on Saturday, 19 September 2009 21:34:28 UTC