Re: Namespace-aware APIs do not need to suck

Michael A. Puls II wrote:
> ...
> I tried the following with Opera:
> 
> (function() {
>     var oldCreateElement = Document.prototype.createElement;
>     Document.prototype.createElement = function() {
>         var args = arguments;
>         if (args.length !== 1 && args.length !== 2)
>             throw new Error("WRONG_ARGUMENTS_ERR");
>         if (args.length === 2)
>             return this.createElementNS(args[0], args[1]);
>         var pattern = /^\{(.+)\}(.+)$/g;
>         var ref = this;
>         var el = null;
>         args[0].replace(pattern, function(match, ns, name) {
>             el = ref.createElementNS(ns, name);
>         });
>         return el !== null ? el : oldCreateElement.call(this, args[0]);
>     };
> })();
> var x = document.createElement("{http://www.w3.org/1999/xhtml}div");
> var y = document.createElement("http://www.w3.org/1999/xhtml", "div");
> var z = document.createElement("div");
> alert(x);
> alert(y);
> alert(z);
> 
> Using the first way seems pretty cool by me fwiw.
> ...

Very cool.

So how do we proceed?

At TPAC I pointed out that we *could* enhance APIs with respect to 
treating namespaces, and I was told there was no proposal.

So here is a proposal. Should we expand it? For instance with respect to 
  obtaining information from an existing DOM node, or with respect to 
traversing the DOM?

BR, Julian

Received on Thursday, 19 November 2009 15:10:24 UTC