DOM creation functions and map

35 views
Skip to first unread message

Joe Gibbs Politz

unread,
Nov 16, 2012, 8:43:14 AM11/16/12
to fla...@googlegroups.com
The DOM creation functions (e.g. UL, LI, P), work when applied to
single arguments, e.g. (behavior from HEAD):

> ['a','b'].map(function(letter) { return LI(letter); });
[<li>a</li>, <li>b</li>]

But trying to use the LI function directly results in bizarreness:

> ['a','b'].map(LI)
[<li>"a""0""a""b"</li>,<li>"b""1""a""b"</li>]

Too much/not enough cleverness with the arguments object maybe?

Arjun Guha

unread,
Nov 19, 2012, 10:19:09 AM11/19/12
to Flapjax
Yeah, something like that is wrong.


Leo Meyerovich

unread,
Nov 19, 2012, 3:50:22 PM11/19/12
to fla...@googlegroups.com
The map implementation probably passes LI the argument list (<data>, <index>, <dataList>). The behavior is "as-intended" . Variable arity of LI lets you write DIV(SPAN(), A()), which is common.

I'm tempted to say that the solution is something like

A) a "single"/first combinator:

['a','b'].map(single(LI))

B) Smarter LI that detects map

LI can look at the call chain or arguments to see if that's what is going on. 


I'm guessing A >> B because there are many implementations of map and map-like constructs out there.


- Leo
Reply all
Reply to author
Forward
0 new messages