我的代碼:如何刪除JavaScript對象(約翰Resig的 - 簡單的繼承)?
myobj = new Object();
classes.testegy = Class.extend({
init: function (token) {
console.log("test egy");
setInterval(function() {
console.log('hello');
}, 300);
},
testt: function() {
console.log("luli");
}
});
classes.testketto = Class.extend({
init: function (token) {
console.log("test ketto");
}
});
classes.site = Class.extend({
init: function (token) {
var myobj = new Object();
myobj.lel1 = new classes.testegy();
myobj.lel2 = new classes.testketto();
console.log(myobj);
delete myobj.lel1;
myobj.lel1.testt();
}
});
var class = new classes.site();
如果我刪除myobj.lel1對象,它會被刪除,但去的setInterval在testegy類。爲什麼?我怎樣才能完全刪除對象?由於
編輯:
一些例子,在不使用的setInterval,使用點擊,和控制檯日誌。
classes.testegy = Class.extend({
init: function(token){
console.log("test egy");
$(".piii").live("click", function() {
console.log("hello");
});
},
foo: function() {
console.log("pina");
}
});
classes.testketto = Class.extend({
init: function(token){
console.log("test ketto");
}
});
classes.site = Class.extend({
init: function(token){
var myobj = new Object();
myobj.lel1 = new classes.testegy();
myobj.lel2 = new classes.testketto();
console.log(myobj);
delete myobj.lel1;
myobj.lel1 = new classes.testegy();
delete myobj.lel1;
myobj.lel1 = new classes.testegy();
delete myobj.lel1;
myobj.lel1 = new classes.testegy();
}
});
回報:1個單擊事件 - > 4X點擊= 4X控制檯日誌:(創建它4陰影對象
您還需要調用'clearInterval' –