A section from the tutorial on template strings at this link includes an interesting example:
var say = "a bird in hand > two in the bush";
var html = htmlEscape `<div> I would just like to say : ${say}</div>`;
// A basic tag function
function htmlEscape(literals, ...placeholders) {
let result = "";
...
// Combine the literals with the placeholders
for (let i = 0; i < placeholders.length; i++) {
result += literals[i];
result += placeholders[i]
Can we generate the exact same escaped input string if the order of placeholders is changed? What happens if the placeholder is placed before the literal text?
Explanation
The creator of the html escape function assumes that the first literal should be output first. But what if the placeholder ${say}
is positioned first? In essence, do tag functions have the ability to determine the sequence of placeholders and literals used?