📅  最后修改于: 2022-03-11 15:01:59.835000             🧑  作者: Mango
'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()