The following code does not work. It wants to bind the variable i at the moment the line in backquotes is seen, and of course gets an error.
const template = `this is line ${i}`
for (i = 1; i < 5; i++) {
console.log(template);
}
Desired output:
this is line 1
this is line 2
this is line 3
this is line 4
You can see what I want: I want a late-binding template that will bind variables at the last possible moment. The example here is only a small simplification of what I really want to do, which involves an array of template strings one of which will be used.
Does JavaScript have a library for this sort of thing?