Converting strings to template strings

Andrea Giammarchi andrea.giammarchi at
Sun Mar 22 10:46:50 UTC 2015

There's no such functionality indeed but you might want to have a look at
this gist:

It gives you the ability to write `'test1 ${1 + 2} test2 ${3 + 4}'
.template();` and read `test1 3 test2 7` or to pass an object similar to
.Net String.format so that your Stack overflow code would be like the


let a = "b:${b}";
let b = 10;


// or



You pass named properties and it works with nested properties too (i.e.

It does use Function which is safe, compared to eval, and needed to
eventually de-opt from 'use strict' but of course you could write your own
parser avoiding Function completely.

Finally, I agree it would be nice to be able to have a standard way to
template strings in JS, the templating as it is plays very poorly with
runtime generated strings, using eval for that looks the dirtiest thing on


On Sun, Mar 22, 2015 at 10:05 AM, KOLANICH <kolan_n at> wrote:

> I needed a functionality but haven't found it.
> See
> for more details.
> I think that this should be included into standard;
> Also we need a standard format string functionality like
> and
> <>
> _______________________________________________
> es-discuss mailing list
> es-discuss at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list