Access to static properties via this.constructor in typescript

前端 未结 6 2303
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-18 13:49

I want to write es6 class:

class SomeClass {
    static prop = 123

    method() {
    }
}

How to get access to static prop from <

6条回答
  •  眼角桃花
    2021-02-18 14:40

    It's a bit dirty, but this code works for me in the Typescript Playground:

    class SomeClass {
        static prop = 123;
    
        constructor() {
            console.log(this.constructor["prop"]);
        }
    
    }
    
    var a = new SomeClass();
    

提交回复
热议问题