Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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()
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to change style class by using onclick function with multiple buttons in react js 
Javascript :: Laravel bootstrap 5 install popper.js error 
Javascript :: put my angular project in subfolder. 500 INTERNAL ERROR 
Javascript :: how-to-avoid-to-exceed-rate-limit-by-using-discord-js-api 
Javascript :: mangoose filter collection based on string match 
Javascript :: react native multiline cursor on first line 
Javascript :: teste google script 
Javascript :: how to autoclose paranthesis in javascript input 
Javascript :: on first time this.file.readAsDataURL not working ios 
Javascript :: make the background color of page in the loading js 
Javascript :: JSDOM - serialize() // returns dom as string 
Javascript :: chartJS Timeline with images 
Javascript :: javascript how to give variable names inside for loop corresponding to value of iterator javascript 
Javascript :: convert python to js online 
Javascript :: symbols with object.assign 
Javascript :: json report plugin 
Javascript :: different db connectons depending on env in typeorm 
Javascript :: signalwire instaall in node 
Javascript :: react userefrence example 
Javascript :: filter object javascript es6 
Javascript :: join-an-array-by-a-comma-and-a-space 
Javascript :: three js div over orbitcontrol 
Javascript :: javascript look hack 
Javascript :: connection string in static class 
Javascript :: mongoose remove more than 1 item 
Javascript :: how to change text in paragraph javascript 
Javascript :: web audio complex example 
Javascript :: discord.js change role permissions 
Javascript :: show each element of an array in a different line 
Javascript :: put text inside an object javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =