3 ms·
Woa there! Why would JavaScript have `with` if you weren't intended to use it‽ How about: let applyTemplate = template => object => { with(object)
by skrebbel 7y ago
Woa there! Why would JavaScript have `with` if you weren't intended to use it‽ How about:
let applyTemplate = template => object => {
with(object) {
return eval("`"+template+"`");
}
}
- dgb23 7y agoFrom the MDN docs: > Use of the with statement is not recommended, as it may be the source of confusing bugs and compatibility issues. See the "Ambiguity Contra" paragraph in the "Description" section below for details. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/with https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- madeofpalk 7y agoThat's the joke? Use of new Function and eval is also generally not recommended.
- bigblind 7y ago"Living a little" is not recommended, because it may lead to confusing situations.
- bregma 7y agoIt's just so beautiful. I can't stop looking.