- From: Aryeh Gregor <ayg@aryeh.name>
- Date: Sun, 2 Oct 2011 16:10:51 -0400
- To: Olli@pettay.fi
- Cc: Ojan Vafai <ojan@chromium.org>, Boris Zbarsky <bzbarsky@mit.edu>, Robin Berjon <robin@berjon.com>, www-dom@w3.org
On Sun, Oct 2, 2011 at 6:38 AM, Olli Pettay <Olli.Pettay@helsinki.fi> wrote: > Why? Why couldn't there be separate method(s) which take string/array etc > and keep the old appendChild etc as they are now (in DOM 3, not in latest > DOM 4 draft) I concur with this. Reasons to prefer separate methods are 1) It's unclear to someone reading the code whether the argument is interpreted as plaintext or HTML. If you do node.appendChild('<div>'), is that supposed to append a text node or an element? Separate methods named things like appendText or insertTextBefore would be much clearer, and not much longer if at all. 2) It's more consistent with other DOM APIs -- overloading on argument type is rare in the DOM. What examples are there currently? 3) It allows easier feature-testing: 'appendText' in Node.prototype instead of having to try it and see if it throws. (Not that this is something likely to be feature-tested much.) 4) It allows the argument to behave like a real string argument, with anything passed to it cast to a string, instead of throwing. JavaScript is weakly typed, and authors are not used to distinguishing much between 42 and "42". These reasons aren't necessarily compelling, but are there any reasons to overload?
Received on Sunday, 2 October 2011 20:11:41 UTC