I have working code, but I am forced to declare the list of possible errors inside the constructor scope, and I am not pleased with that.
#Pugjs es literals how to
They receive the parts of a Template String as arguments and you can then decide how to use the strings and substitutions to determine the final output of your string.I am starting to use template literals to make a error generator. One of the most significant features they bring are tagged templates - a critical feature for authoring such DSLs.
These include better ways to do string & expression interpolation, multiline strings and the ability to create your own DSLs.
Template Strings bring many important capabilities to JavaScript. You may also be interested in ES6 Equivalents in ES5, which demonstrates how to achieve some of the sugaring Template Strings bring using ES5 today. Check out our Template Strings sample over on the Chrome samples repo if you'd like to try them out. Practically speaking if you would like to use them in production today, they're supported in major ES6 Transpilers, including Traceur and 6to5. Template Strings are in Chrome 41 beta+, IE Tech Preview, Firefox 35+ and io.js. Template Strings can contain placeholders for string substitution using the $ ` # Summary Substitution allows us to take any valid JavaScript expression (including say, the addition of variables) and inside a Template Literal, the result will be output as part of the same string. One of their first real benefits is string substitution. So far, Template Strings haven't given us anything more than normal strings do. A template string could thus be written as follows: var greeting = ` Yo World! ` Template Strings use back-ticks ( ``) rather than the single or double quotes we're used to with regular strings. Rather than stuffing yet another feature into Strings as we know them today, Template Strings introduce a completely different way of solving these problems.