2017-04-20 61 views
0

如何将绑定到onclick监听器的动态创建对象的方法?在类方法中绑定带有对象参数的onclick listner

class PanelWindow { 
    constructor(windowMenager) { 
     this.windowMenager = windowMenager; 

     this.makeDomElements(); 
     this.setId(windowMenager); 
    } 

    setId(windowMenager) { 
     this.id = windowMenager.getId(this); 
     console.log(this.id); 
    } 

    createDomElements() { 
     var pn_header_close = document.createElement("div"); 
     pn_header_close.onclick = this.closeWindow; 
    } 

    closeWindow() { 
     this.window.style.display = "none"; 
    } 

} 

我想绑定到pn_header_close.onclick这一点: this.closeWindowWindowActions.closeWindow(this.id, this.windowMenager)

回答

0
在构造函数

包括:

this.closeWindow = this.closeWindow.bind(this); 
相关问题