Claude Pache claude.pache at
Wed Aug 12 15:26:31 UTC 2015

> Le 12 août 2015 à 15:41, Edwin Reynoso <eorroe at> a écrit :
> 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"
> ```

If you look closely, `String.substitute` is just the `with` statement resurrected:

with ({ year: 2015 }) { 
    `This year is ${year}` 

At first glance, the `with` statement looked like a great idea, but in fact, it makes static analysis difficult for both human and machines: In short: What do you expect from: 

let shift = 1; 
String.substitute( obj, `This year is ${year + shift}` );

 when you don’t know a priori whether `obj` has a `year` property, and whether it has a `shift` property?


More information about the es-discuss mailing list