• Empleos
  • Bootcamp
  • Sobre nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Publicar empleo
    • Nuestro proceso
    • Precios
    • Pruebas Online
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

115
Vistas
Javascript class this.target is different from method and constructor

enter image description here

I want to get div.timer but this.target is always return div#root.

here's my code.

export default class Component {
    target: Element | null
    constructor(target?: Element) {
        this.target = target || $('#root')
    }
export default class Timer extends Component {
    target: Element | null
    constructor(target: Element | null, ) {
        super()
        this.target = target || $('.timer')
        console.log(this.target)                 // this return div.timer
    }
    template() {
        console.log('target', this.target)       // thus return div#root
        return ``
    }
}

over 1 year ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos