google / incremental-dom

An in-place DOM diffing library
http://google.github.io/incremental-dom/
Apache License 2.0
3.54k stars 180 forks source link

How to bind "this" to "elementOpen" #390

Closed sooboy closed 6 years ago

sooboy commented 6 years ago

Hello, I am trying to bind "this" to "elementOpen":

class Link extends Render implements ILinker {
    constructor(
        public title: string,
        public url: string,
    ) {
        super();
    }

    public click() {
        window.location.href = this.url;
    }

    public render() {
        elementOpen("a", null, null,
            "onclick", ()=>console.log("ok",this),
        );
        text("123");
        elementClose("a");
    }
}

when I click :

image

this is undefined,How to bind this.click to elementOpen

"onclick", ()=>this.click(),

My expression is not very accurate, I hope you can understand;

sooboy commented 6 years ago

I have solved it.