> Le 12 août 2015 à 15:41, Edwin Reynoso <[email protected]> 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:

```js
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: 

```js
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?

—Claude

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to