I'm writing a class named Graph using JavaScript. Code is like following:
export default class Graph {
constructor(props) {
document.querySelector('#slider').addEventListener('change', function (){
// Uncaught ReferenceError: fun is not defined
this.fun()
})
}
fun () {
// some code
}
}
Of course, code like this can't work.Since in the callback function, 'this' only points to the slider.Browser also complained about reference error after I deleted 'this'. Is there some method to fix this problem?