Is there a way to continue working with a template after the initial expression/assignment?
As expected, this works:
const testTag = (strings, ...values) => console.log(strings, values);
testTag `${'this'}${'is'}${'test'}`;
> ["", "", "", ""], raw: ["", "", "", ""]
> ["this", "is", "test"]
This doesn't:
const testTag = (strings, ...values) => console.log(strings, values);
const testLiteral = `${'this'}${'is'}${'test'}`;
testTag testLiteral;
> Uncaught SyntaxError: Unexpected identifier
const testTag = (strings, ...values) => console.log(strings, values);
const testLiteral = `${'this'}${'is'}${'test'}`;
testTag `${testLiteral}`;
> ["", ""], raw: ["", ""]
> ["thisistest"]
const testTag = (strings, ...values) => console.log(strings, values);
const testLiteralMaker = () => `${'this'}${'is'}${'test'}`;
testTag `${testLiteralMaker()}`;
> ["", ""], raw: ["", ""]
> ["thisistest"]
const testTag = (strings, ...values) => console.log(strings, values);
const testLiteralMaker = () => `${'this'}${'is'}${'test'}`;
testTag(testLiteralMaker());
> thisistest
> []
const testTag = (strings, ...values) => console.log(strings, values);
const testLiteralMaker = () => `${'this'}${'is'}${'test'}`;
testTag(...testLiteralMaker());
> t
> ["h", "i", "s", "i", "s", "t", "e", "s", "t"]
((strings, ...values) => console.log(strings, values))(`${'this'}${'is'}${'test'}`)
> thisistest
> []
((strings, ...values) => console.log(strings, values))((() => `${'this'}${'is'}${'test'}`)())
> thisistest
> []
I'm interested in a way that I can write reusable code using template literals, but I cannot understand how two functions can meaningfully share them.