4 ms·
Can someone tell me what possible value this has?
by brockers 8y ago
Can someone tell me what possible value this has?
- deleted 8y ago[deleted]
- blktiger 8y agoLook at what this does with the feature - https://polymer.github.io/lit-html https://polymer.github.io/lit-html
- rhacker 8y agoI saw that a while back, now I know how they did that!
- robmaister 8y agoJob security
- doomslice 8y agoThey're called tagged templates: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_templates https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... Apart from the other examples, I've also seen them be used for internationalization. http://i18n-tag.kolmer.net/ http://i18n-tag.kolmer.net/
- toast0 8y agoSomeone wandered in from perl5? (I say that as a person who enjoys perl)
- naranha 8y agoIt can be used for escaping values for example var query = sql`select * from user where id=${id}` Similar for html, preventing injection. You just need to implement the corresponding functions. For example https://github.com/felixfbecker/node-sql-template-strings https://github.com/felixfbecker/node-sql-template-strings
- rbrcurtis 8y agoI don't see how this is better than var query = sql(`select * from user where id=${id}`);
- naranha 8y agoYes that's something the author does not explain well. sql is not a normal function but a special template "handler" with fixed parameters.
- egeozcan 8y agoIn your example, you get the concatenated string. If you use the tags, you can access the parts.
- gramstrong 8y agoIt's just a tiny language feature, removing the parenthesis is not the point of the template literal. FWIW, I like the way it looks for styled-components: const NameTag = styled.div` font-size: 12pt; margin: 3px; `;
- basil-rash 8y agoIn this case the sql function can not escape the id. If you were to use a tagged template, it could.
- deleted 8y ago[deleted]