3 ms·
Tagged templates probably won’t help, or will be quite messy. But you can just use a thunk with some parameter destructuring: const tpl = ({ name }) =>
by cluckindan 1y ago
Tagged templates probably won’t help, or will be quite messy. But you can just use a thunk with some parameter destructuring:
const tpl = ({ name }) =>
`hello ${name}`;
const n1 = tpl({ name: "joe" });
const n2 = tpl({ name: "bob" });
Or if you don’t like the duplication of property names, you could do it without destructuring:
const tpl = (o) =>
`hello ${o.name}`;
Look for the free online book ”You don’t know JS”, it is good reading.