Re: Element.createElement proposal
Johnny Stenback <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.dom |
|---|---|
| Message-ID | <[email protected]> |
On 08/10/2009 05:22 PM, Jonathan Watt wrote:
> On 2009-08-11 1:38 AM, Johnny Stenback wrote:
>> On 08/05/2009 01:52 AM, Jonathan Watt wrote:
>>> Hi guys,
>>>
>>> I've been thinking about what we can do to simplify the creation of new elements
>>> using the DOM. I came up with a few ideas in the SVG WG, and I wondered what you
>>> think about the following one (and how implementable it is in Mozilla). Please
>>> bear with me to the end of the email.
>>>
>>> It's really tedious and error prone that you have to do:
>>>
>>> c = document.createElement('NS-people-dont-know-or-want-to-type', 'circle');
>>> c.setAttribute('cx', '10');
>>> c.setAttribute('cy', '10');
>>> c.setAttribute('r', '10');
>>> svgElement.appendChild(c);
>>>
>>> Much better would be:
>>>
>>> c = svgElement.createElement('circle', { cx: 10, cy: 10, r: 10} );
>>> svgElement.appendChild(c);
>>>
>>> or even just:
>>>
>>> c = svgElement.createChild('circle', { cx: 10, cy: 10, r: 10} );
>>>
>>
>> I still think element creation belongs on document objects more than it
>> does on elements. How about adding a createSVGElement method to our
>> documents instead? Since it'd be a new method, we could change the
>> signature of that to do things that are more developer friendly? Given
>> that HTML5 supports mixed in SVG, this would make some amount of sense
>> at least on HTML documents. Same goes for MathML too, I guess...
>
> Hmm. I'm not all that keen on the idea of adding separate methods like
> createSVGElement, createMathMLElement and createXULElement (and
> createHTMLElement?) for each namespace we may support now or in the future.
> Allowing elements to create more elements on the other hand is less of a problem
> to me I guess.
I hear ya', and I'm not suggesting we do that for everything, only where
there's a real benefit to it, as I think is the case with SVG, given the
very complex DOM's you might find there.
What I don't like about svgElement.createElement() is that it seems a
bit odd to have to find an element to create one, which makes the case
where you're inserting SVG into a document where there is no existing
SVG such that developers still need to type out that namespace URI they
don't want to type out. svgElement.createChild() doesn't make any sense
to me as there's no child relationship between the element you use for
creating and the element that gets created.
> Jonathan
--
jst