I'd like to access a value that exists on the object where a tagged template literal is located, without introducing extra syntax.
function myTemplate(str: TemplateStringsArray) {
console.log(this.myValue)
return str[0]
}
function Create(options) {
return options
}
const value = Create({
myValue: 'something',
template: myTemplate`
some text
`
})
I would like the console.log(this.myValue)
to print the value located on the object it's nested within.
The following works, but I don't want to have to bind the template like this.
const value = Create({
myValue: 'something',
template: myTemplate.bind(this)`
some text
`
})
I tried binding it in the Create
function like so:
function Create(options) {
options.template.bind(options)
return options
}
But of course, it doesn't work as the tag has already been evaluated.