removeeventlistener not working in class javascript

Solutions on MaxInterview for removeeventlistener not working in class javascript by the best coders in the world

showing results for - "removeeventlistener not working in class javascript"
Nelson
07 Jul 2018
1'use strict'
2class Mouser {
3  constructor () {
4    this.counter = 0
5    this.clicked = function (event) {
6      this.counter ++
7      console.log('clicks:', this.counter)
8      if (this.counter >= 10) this.remove()
9    }
10    // save the click handler so it can be used in multiple places
11    this.clickHandler = this.clicked.bind(this);
12    window.addEventListener('click', this.clickHandler)
13  }
14
15  remove () {
16    console.log('Removing click listener') // this line runs ..
17    window.removeEventListener('click', this.clickHandler)
18  }
19}
20
21var mouse = new Mouser()
22