Is there destructor in typeScript

别说谁变了你拦得住时间么 提交于 2019-11-30 16:46:57

JavaScript uses garbage collection to automatically delete objects when they are no longer referenced. There is no concept of destructors or finalizers.

You can't observe when an object is deleted by the garbage collector, nor is it predictable.

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
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!