使用函数绑定未定义事件

问题描述 投票:0回答:2
class Foo {
    construtor(){
        this.ref = document.querySelector('.foo');
        this.bind('click', onClick)
    }
    onClick(event) {
        // event is undefined
        console.log(event)
    }
    bind(event,action) {
        this.ref.addEventListener(event, action.bind(this));
    }
}

请告诉我event参数如何传递给onClick函数。

javascript events bind
2个回答
© www.soinside.com 2019 - 2024. All rights reserved.