在 Firefox 和 Firefox Developer 上我无法在控制台上看到类的元素

问题描述 投票:0回答:1

当我使用 console.log(class) 或使用字符串模板时,我为类的每个对象放置的元素显示未定义

mokepones.forEach((mokepon) => {
  MokeponChoice = `
    <input type="radio" name="mascota" id=${mokepon.nombre} />
    <label class="tarjetas-mokepon" for=${mokepon.nombre}>
      <p>${mokepon.nombre}</p>
      <img src=${mokepon.foto} alt="${mokepon.nombre}">
    </label>
  `
  contenedorTarjetas.innerHTML += MokeponChoice
  console.log(mokepon.nombre)
})

是否有插件或其他东西可以让我在 Firefox Developer 中看到这些元素?

我尝试下载 Firefox Developer 看看是否可以看到它

编辑:这是课程

class Mokepon {
    constructor(nombre, foto, vida) {
        this.nombre
        this.foto
        this.vida
        this.ataques = []
    }
}

let hipodoge = new Mokepon('Hipodoge', './assetsMP/mokepons_mokepon_hipodoge_attack.webp', 5)
let capipepo = new Mokepon('Capipepo', './assetsMP/mokepons_mokepon_capipepo_attack.webp', 4)
let ratigueya = new Mokepon('Ratigueya', './assetsMP/mokepons_mokepon_ratigueya_attack.webp', 3)

hipodoge.ataques.push(
    { nombre: '💧', id: 'boton-agua' },
    { nombre: '💧', id: 'boton-agua' },
    { nombre: '💧', id: 'boton-agua' },
    { nombre: '🌱', id: 'boton-tierra' },
    { nombre: '🔥', id: 'boton-fuego' },
)

capipepo.ataques.push(
    { nombre: '🌱', id: 'boton-tierra' },
    { nombre: '🌱', id: 'boton-tierra' },
    { nombre: '🌱', id: 'boton-tierra' },
    { nombre: '💧', id: 'boton-agua' },
    { nombre: '🔥', id: 'boton-fuego' },
)

ratigueya.ataques.push(
    { nombre: '🔥', id: 'boton-fuego' },
    { nombre: '🔥', id: 'boton-fuego' },
    { nombre: '🔥', id: 'boton-fuego' },
    { nombre: '💧', id: 'boton-agua' },
    { nombre: '🌱', id: 'boton-tierra' },
)

mokepones.push(hipodoge, capipepo, ratigueya)

这是页面上的样子

javascript html firefox firefox-developer-tools
1个回答
0
投票

您需要将

constructor parameters
传递给
class properties

Firefox
不是这里的问题。

class Mokepon {
    constructor(nombre, foto, vida) {
        this.nombre = nombre
        this.foto = foto
        this.vida = vida
        this.ataques = []
   }
}
© www.soinside.com 2019 - 2024. All rights reserved.