Elegant way to generate string from tagged template?

Glen Huang curvedmark at gmail.com
Tue Dec 23 20:58:16 PST 2014


This returns true in traceur:

```js
function tag(templateObj, ...args) {
	return String.raw({raw: templateObj}, ...args);
}

let content = "world";
console.log(tag`hello\n${content}` === `hello\n${content}`);
```

Looks like problem solved. :)

> On Dec 24, 2014, at 12:44 PM, Brendan Eich <brendan at mozilla.org> wrote:
> 
> Clever -- treat the cooked values as raw. Should work -- test in Traceur?
> 
> /be
> 
> Glen Huang wrote:
>> On second thought, make it could be just as simple as this?
>> 
>> function tag(templateObj, ..args) {
>> 	return String.raw({raw: templateObj}, …args);
>> }



More information about the es-discuss mailing list