4 ms·
How does something like this work: template() { return ` <span>${greeting}, ${host.name}!</span> <button onclick="cha
by spankalee 3y ago
How does something like this work:
template() {
return `
<span>${greeting}, ${host.name}!</span>
<button onclick="changeGreeting">Change Greeting</button>
`;
}
I don't see `greeting` or `host` defined anywhere in scope, so this should be an error. Did you forget to prefix them with `this.`?
- evan_ 3y agoHere’s the function that evaluates the template: with (this.state) { return eval(`(function ${this.template.toString().replace(/^\s*function\s+/,'')}())`); } So it’s effectively turning everything in `this.state` into a local var and evaluating the code in the template function in that context.
- spankalee 3y agoThat's so difficult for humans and tools to reason about. It would completely break intellisense and lots of lint rules. What's the reason for this?