当父对象被销毁时,Javascript的setInterval被终止了吗?
我有一个全局variablesglobal.loggedInUsers = {};
。 这个对象被用来作为和字典被占用唯一的key:value
对。
关键是唯一的一个值是一个帐户对象。
function Account(hash, jsonData) { this.hash = hash; this.accountJson = JSON.parse(jsonData); this.pongUpdate = 20; setInterval(function() { // Stuff happens here blah blah }, 1000); } Account.protoype....
在我的代码最终我调用删除function
delete(loggedInUsers.key);
因为Account
类包含了setInterval
调用,如果Account
对象被删除了,那么setInterval会停止还是必须将setInterval存储在一个variables中呢?
setInterval
的函数的引用存在,并且因为您没有使用clearInterval
– 它将继续运行。
var t = 1; function Account() { this.a = setInterval(function() { console.log('a ' + t) t += 1 }, 1000); } a = new Account(); setTimeout(function() { delete(a) }, 3000)