On Fri, Aug 3, 2012 at 1:25 AM, Claus Reinke <[email protected]> wrote:
>> let tmpl = html`
>> <table>
>> $for address in addresses ${
>> html`<tr>${"first"}</tr><tr>${"last"}</tr>`
>> }
>> </table>`;
>
>
> let tmpl = addresses => html`
> <table>
> ${addresses.forEach(address=>
> html`<tr>${address.first}</tr><tr>${address.last}</tr>`
> ).join('\n')
> }
> </table>`
>
> would be my guess? Similarly for the localization example
> in the blog post: arrow functions should make it relatively painless to make
> the template parameters explicit.
>
> Of course, building HTML from nested templates is not the
> same as filling a flat HTML template with user input, so I'm
> not sure what the implicit encoding of template parameters
> will do to this approach.
> Does this make sense?
Yes. But you need to say ".map(" rather than ".forEach(" above. See
<http://wiki.ecmascript.org/doku.php?id=harmony:quasis#nesting>.
Thanks for pointing out how much fat arrows help for this use case. I
knew it would help but hadn't expected it to help that much. Nice!
> Claus
>
>
>> // Use
>> console.log(tmpl({
>> addresses: [
>> { first: Jane, last: Bond },
>> { first: Lars, last: Croft },
>> ]
>> }));
>
>
>
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
--
Cheers,
--MarkM
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss