Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS code chrome debug, why is this undefined?

I`m using VS code and chrome debugger extension . The code below is executed without errors and produces the expected result, however i see that 'this' is undefined in WATCH section.

class Q {
    constructor() { 
        this.arr = [1,2,3]
    }
    log(e) {
        console.log(e)
    }
    test() {
        this.arr.forEach(e => {
            this.log(e); // this is undefined when debugging
        })
    }
}

const f = new Q().test()

what am I doing wrong?

like image 592
deemaagog Avatar asked Oct 17 '22 22:10

deemaagog


1 Answers

To avoid conflicts with the this JavaScript keyword, TypeScript renames this into _this when transpiled. Try watching for _this instead.

like image 114
BernardV Avatar answered Oct 21 '22 00:10

BernardV