In python, you can do variable string interpolation like this:
song_context = { "adjective": "funny" }
ella_sings = "my {adjective} valentine".format(**song_context)
Here, the song_context
object formats variables in the ella_sings
string.
In ES6 is there a built-in way to do something like this with template literals? I'm looking for a quick way to explicitly define a substitution space for a given string. Ex:
const song_context = { adjective: "funny" }
const ella_sings = `my ${adjective} valentine`.format(song_context)
Context: I know other ways to do this, e.g. use a template library or do multiple find and replace, but am wondering if any portion of ES6 supports this use case out of the box. I skimmed the template literal part of the ECMAScript 6.0 standard and it pretty clearly states "Let ctx be the running execution context"
but it seems kind of hard to believe they wouldn't provide a way to be more explicit about the context when necessary.