- From: Garrett Smith <dhtmlkitchen@gmail.com>
- Date: Sat, 17 Sep 2011 22:11:35 -0700
- To: Anne van Kesteren <annevk@opera.com>
- Cc: public-script-coord@w3.org
On 9/17/11, Anne van Kesteren <annevk@opera.com> wrote: > For the DOM we have this idea of having a method that can conveniently > create an element, set its attributes, event handlers, and child nodes. > However, to keep the method convenient some of those need to become > optional and therefore it requires some kind of overloading, which is > where things become problematic. > > Maybe there is a better design, but so far we have something like this: > > create(name) > create(name, attributes) > create(name, children) > create(name, attributes, children) > create(name, attributes, eventhandlers, children) > > name is a string. > > attributes is an object. > So is an Array. > eventhandlers is an object. > > children is either a Node or string, or an array of Nodes and strings. > A Node is an object. > Examples: > > create('h1', 'Welcome!') > create('button', {name: 'command', value: 'search'}, {onclick: teehee}, > 'Search') > create('p', {title: 'hi'}, [node, node2]) > > The problem is however that arrays and objects are not really > distinguishable unless you do "evil things". > > Anyone with ideas? > Just because jQuery is popular, that does not mean you should copy that API approach. Your new "create" method does not describe what it does. Go on, I dare you to name the method by what it actually does. Then there's the issue [[Scope]] of event handler or the likelihood of augmenting the attributes/properties confusion by using properties to set attributes. -- Garrett
Received on Sunday, 18 September 2011 05:12:03 UTC