I am creating functions containing strings that need interpolation:
let createPFunc = (string) => {
return () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log(`${string}`);
resolve();
}, 2000);
})
}
}
let f1 = createPFunc('String 1: ${string}');
let f2 = createPFunc('String 2: `${string}`');
f1(`search 1`).then(() => f2('search 2'))
What it prints is:
String 1: ${string}
String 2: `${string}`
I want it to print:
String 1: search 1
String 2: search 2
I tried different quoting variations, but can't find a combination that works.
How can I perform interpolation twice, or delay interpolation so ${string}
is resolved when the function is called (instead of when the function is created)?