2017-04-20 42 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); 
相關問題