有了这个代码,当按下一个键时,‘index’就变成了NaN. 为什么,以及如何正确地进行呢?
const Key = function(){
this.Index = 0;
}
Key.prototype.storeKey = function(key){
this.Index++;
console.log(this.Index);
}
const listener = new Key();
addEventListener("keydown", listener.storeKey); // <---- does not work
listener.storeKey(); // <--- does work
通过EventListener原型函数更改对象中的值