I love the new name “template strings” for “quasi literals”. Only “tag” seem 
inferior to “quasi handler”, because that former term is already used in HTML.

Template strings are not ideally suited for templates (think Mustache), as 
expressed by Nicholas Zakas [1]. Any ideas for helping here? The best I can 
come up with is:

    // Define
    let tmpl = html`
    <table>
        $for address in addresses ${
            html`<tr>${"first"}</tr><tr>${"last"}</tr>`
        }
    </table>`;

    // Use
    console.log(tmpl({
        addresses: [
            { first: Jane, last: Bond },
            { first: Lars, last: Croft },
        ]
    }));

Custom syntax: The dollar sign ($) starts a command. As substitutions always 
have to be in curly braces, that doesn’t clash with template string syntax.

This could be OK for quick and dirty templates stored inside source code, with 
the advantage of the ES.next parser handling nesting for you.

[1] 
http://www.nczonline.net/blog/2012/08/01/a-critical-review-of-ecmascript-6-quasi-literals/

-- 
Dr. Axel Rauschmayer
a...@rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to