W3C home > Mailing lists > Public > public-script-coord@w3.org > July to September 2011

Distinguishing objects and arrays?

From: Anne van Kesteren <annevk@opera.com>
Date: Sat, 17 Sep 2011 23:57:49 +0200
To: public-script-coord@w3.org
Message-ID: <op.v1y3anre64w2qv@annevk-macbookpro.local>
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

This archive was generated by hypermail 2.3.1 : Wednesday, 8 May 2013 19:30:04 UTC