I have a class that was created like this:
function T() {
this.run = function() {
if (typeof this.i === \'undefined\')
this.i = 0;
To delete an instance, in JavaScript, you remove all references pointing to it, so that the garbage collector can reclaim it.
This means you must know the variables holding those references.
If you just assigned it to the variable x
, you may do
x = null;
or
x = undefined;
or
delete window.x;
but the last one, as precised by Ian, can only work if you defined x as an explicit property of window
.
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 workdelete eval['func']
-- not workdelete window['SAFunc']
-- not workFunction - 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 ;)