0

I'm having problem with addEventListener inside modul. I want to change propety of object by addEventListner inside class, so i wrote a simple example what i mean. What to do to make it work ?

import Person from './new.js'

const citizen = new Person();
citizen.changeName();
console.log(citizen.name); // expect to see event.traget, see null
export class Person{
    constructor(){
        this.name = null ;
    }

    changeName(){
        document.addEventListener("click", ()=>{
            this.name = event.target;
        })
    }
}

0 Answers0