Distinguishing objects and arrays?

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, 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.


create('h1', 'Welcome!')
create('button', {name: 'command', value: 'search'}, {onclick: teehee},  
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

Received on Saturday, 17 September 2011 21:58:20 UTC