With TypeScript: unable to refer to 'this' (class) from inside a function

前端 未结 3 1284
猫巷女王i
猫巷女王i 2020-12-21 05:50

I\'m learning TypeScript and have the following class:

class DetailDriver {

    public get driver() {
        return super.getEntity();
    }

         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-21 06:22

    For reference, you could also just do:

    class SomeClass {
    
        public someMethod() {
            // Do something
        }
        public anotherMethod() {
            var that = this; // Reference the class instance
    
            function someFunction () {
                that.someMethod();
            }
        }
    }
    

提交回复
热议问题