Answers for "removeeventlistener not working in class javascript"

0

removeeventlistener not working in class javascript

'use strict'
class Mouser {
  constructor () {
    this.counter = 0
    this.clicked = function (event) {
      this.counter ++
      console.log('clicks:', this.counter)
      if (this.counter >= 10) this.remove()
    }
    // save the click handler so it can be used in multiple places
    this.clickHandler = this.clicked.bind(this);
    window.addEventListener('click', this.clickHandler)
  }

  remove () {
    console.log('Removing click listener') // this line runs ..
    window.removeEventListener('click', this.clickHandler)
  }
}

var mouse = new Mouser()
Posted by: Guest on April-29-2021

Code answers related to "removeeventlistener not working in class javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language