Delete instance of a class?

后端 未结 2 816
清酒与你
清酒与你 2020-12-09 16:03

I have a class that was created like this:

function T() {
    this.run = function() {
        if (typeof this.i === \'undefined\')
            this.i = 0;
           


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-09 16:36

    Class not same function are different. Not work a delete. Class is system modification.

    class SAFunc {
      method1(){
        console.log("1");
      }
      method2(){
        console.log("2");
      }
    }
    let func  = new SAFunc();
    func['method2']()
    

    Try:

    • delete window['func'] -- not work
    • delete eval['func'] -- not work
    • delete window['SAFunc'] -- not work
    • ...
    • ...

    Function - command work delete

    method1 = function(){
      console.log("func1");
    }
    function method2() {
      console.log("func2");
    }
    var SAFunc = { method3: function() { console.log("func3"); } }
    

    Make ur test... Try:

    • delete window['method1']
    • delete window['method2']
    • delete SAFunc['method3']

    Good fun! i love programming

    Enjoin us ;)

提交回复
热议问题