Is there destructor in typeScript

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



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


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.