- From: Anne van Kesteren <annevk@opera.com>
- Date: Sat, 17 Sep 2011 23:57:49 +0200
- To: public-script-coord@w3.org
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. eventhandlers is an object. children is either a Node or string, or an array of Nodes and strings. 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? -- Anne van Kesteren http://annevankesteren.nl/
Received on Saturday, 17 September 2011 21:58:20 UTC