String.substitute

Edwin Reynoso eorroe at gmail.com
Wed Aug 12 13:41:35 UTC 2015


Could we make the following possible, I can't seem to think of a way to do
it, since template literals are evaluated with the current scope, also
tried with `eval` but shouldn't even use that at all:

```JS
String.substitute( { year: 2015 }, `This year is ${year}` ); // Returns
"This year is 2015"
```

Yes I'm aware I could do the following:

```JS
var obj = { year:2015 }

`This year is ${obj.year}`
```

The point is to get rid of the part where I reference `obj` all the time.

I could just use destructuring:

```JS
var { year } = { year: 2015 }

`This year is ${year}`
```

So yes destructuring takes care of most of this just fine, but the point is
to have a template literal evaluate as a pass reference and not right away.

You can't make your own function and pass in a template literal that's not
evaluated when passed as a reference, I'm not sure if anyone will actually
want this but me. Please let me know. Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150812/6a348da1/attachment.html>


More information about the es-discuss mailing list