Estoy creando una biblioteca simple que convierte objetos JS en componentes de clase JS para registrar y usar en HTML. Lo estoy probando con un objeto simple:
const myEle = { state: { message: `Hello World` }, template: `<p> ${this.state.message} </p>`, style: { color: "red" }, hooks: { onClick: () => alert("Hi!") }, attrs: {}, element: toComp(this.template, this.style, this.state, this.hooks, this.attrs) } Específicamente, el error es con template . lo que me da el error mencionado en el título, a pesar de que this.state.message hace snese ti ne. ¿Por qué está pasando eso?
No puede acceder al objeto durante su inicialización con sintaxis literal de objeto.
Este es javascript inválido:
const obj = { property1: 'hello', property2: property1 };Puede acceder a él después de su inicialización:
const obj = { property1: 'hello', }; obj.property2: property1;