0

I have the simple TypeScript class. Here it is

class Test {
    myMethod() {
        this.func(this.callback);
    }

    private func(callback: Function) {
        console.log(this);
        callback();
    }

    private callback() {
        console.log(this);
    }
}

And when I try to use this class so

new Roadkill.Web.Page.Test().myMethod();

I get the following output in console:

Test {} // output from func()
Window {...} // output from callback

As you can see 'usual' method func treats this as Test class as it expected. But callback method named callback handles this as global object Window and it surprised me. Does anyone know how to use class Test and its members from callback method?

Pupkin
  • 857
  • 2
  • 11
  • 20

0 Answers0