Tagged template strings are one of my favorite parts of ES6. I include them and
generators in my ["ES6 The Awesome Parts" talk][1].
Sample uses from that slide deck, most of them cribbed from the wiki:
```js
// Contextual auto-escaping
qsa`.${className}`;
safehtml`<a href="${url}?q=${query}" onclick="alert('${message}')"
style="color: ${color}">${message}</a>`;
// Localization and formatting
l10n`Hello ${name}; you are visitor number ${visitor}:n! You have ${money}:c in
your account!`
// Regexes
re`\d+${separator}\d+`
// Embedded HTML/XML
jsx`<a href="${url}">${text}</a>` // becomes React.DOM.a({ href: url }, text)
// DSLs for code execution
var childProcess = sh`ps ax | grep ${pid}`;
var xhr = POST`http://example.org/service?a=${a}&b=${b}
Content-Type: application/json
Authorization: ${credentials}
{ "foo": ${foo}, "bar": ${bar} }`;
```
[1]: http://www.slideshare.net/domenicdenicola/es6-the-awesome-parts/23
From: es-discuss [mailto:[email protected]] On Behalf Of Aaron
Powell
Sent: Thursday, March 6, 2014 19:28
To: Axel Rauschmayer; Caitlin Potter
Cc: es-discuss list
Subject: RE: Template strings and templates
On the point of DLS's, are there any example points like the regex one you
posted Axel? I'm curious as to how you would do the transform
________________________________________
Subject: Re: Template strings and templates
From: [email protected]
Date: Fri, 7 Mar 2014 00:46:53 +0100
To: [email protected]
CC: [email protected]
- Regular expressions: https://gist.github.com/slevithan/4222600
- Escaping the variable parts of domain-specific languages
- HTML templates (think Facebook's React)
- Internationalization
Axel
On Mar 7, 2014, at 0:29 , Caitlin Potter <[email protected]> wrote:
What exactly is being accomplished with tagged templates? I mean, what is the
use case? It seems to make certain specific function calls look very different
from a typical function call, the arguments passed in are not very clearly
explained in the draft or wiki, and I have difficulty imagining anyone actually
using these for anything. I would love to hear a solid case for these (I've
been looking for the past few nights, but nothing has shown up). Template
literals are great, but the `tagging` thing seems fishy for the vast majority
of applications.
I'm not saying they shouldn't be included in harmony, i'm just very interested
in finding out what practical task they are meant to accomplish
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss
--
Dr. Axel Rauschmayer
[email protected]
home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com
_______________________________________________ es-discuss mailing list
[email protected] https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss