Re: Element.create(): a proposal for more convenient element creation

On Mon, 1 Aug 2011, Maciej Stachowiak wrote:
> 
>    Creates an element with the specified tag, attributes, and children.
> 
>    tagName - tag name as a string; by default it does "smart" selection 
> of SVG, HTML or MathML namespace. Authors can also use an html: svg: or 
> mathml: prefix to override these defaults.

I'd suggest just always defaulting to HTML and requiring "svg:" and 
"mathml:" prefixes for those namespaces. That makes code easier to read 
(it's obvious what's going on, and you won't accidentally use elements 
from the wrong namespace). It also makes forward-compatibility easier (we 
don't have to worry about adding new elements to the list and what that 
will do to future legacy UAs).


> (And further, you can use xmlns in attribute map to use a custom 
> namespace.)

I wouldn't bother supporting the "xmlns" attribute in this API, but I 
don't feel strongly about this.


>    attributeMap - JS object-as-dictonary or whatever dictionary type is 
> appropriate to the language, or null for no attributes

Optional attribute, too.


>    children… - veridic parameter, can include nodes, strings, or arrays. 
> Strings are converted to text nodes. Arrays are unpacked and treated as 
> lists of nodes/strings. Array support is for cases where you want to 
> have a call-site that may take a veriable-length list, with possible 
> prefix and suffix.

Also optional.


So you could also do:

   var div = Element.create('div');

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

Received on Tuesday, 2 August 2011 01:44:13 UTC