Is there destructor in typeScript

前端 未结 2 1659
盖世英雄少女心
盖世英雄少女心 2021-01-01 08:31

Is there destructor in TypeScript? If not, how can I delete an object? I tried destructor() and ~ClassName() but it didn\'t work.

2条回答
  •  既然无缘
    2021-01-01 08:43

    You can actually

        class MyClass {
            constructor(input1, input2){
                 this.in1 = input1;
                 this.in2 = input2;
             }
    
        }
        let myObject = {};
    
    
        try {
             myObject = {
                 classHandler: new MyClass('1','2')
             }
        } catch (e) {
        } finally {
            delete myObject.classHandler
        }
    

提交回复
热议问题