相关疑难解决方法(0)

删除一个类的实例?

我有一个像这样创建的类:

function T() {
    this.run = function() {
        if (typeof this.i === 'undefined')
            this.i = 0;
        if (this.i > 10) {
            // Destroy this instance
        }
        else {
            var t = this;
            this.i++;
            setTimeout( function() {
                t.run();
            }, 1000);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

然后我初始化它就像 var x = new T();

如果达到10次迭代,我不确定如何从内部破坏这个实例.

此外,我不知道如何在外部销毁它,以防我想在它达到10之前停止它.

javascript

20
推荐指数
1
解决办法
4万
查看次数

“标识符 [...] 已经被声明(...)”。如何在 Chrome Devtools 控制台中取消设置类变量?

在 Chrome 控制台中:

# One
class A {
    constructor(x) { this.x = x }
}

class A {
    constructor(x, y) { this.x = x; this.y = y }
}

VM602:1 Uncaught SyntaxError: Identifier 'A' has already been declared(…)


# Two
class A {
    constructor(x) { this.x = x }
}
delete A
true
class A {
    constructor(x) { this.x = x }
}
VM805:1 Uncaught SyntaxError: Identifier 'A' has already been declared(…)


# Three
A = null
null
class A …
Run Code Online (Sandbox Code Playgroud)

google-chrome google-chrome-devtools

5
推荐指数
1
解决办法
3180
查看次数