0
如果垃圾收集器具有代碼中的某些引用,則垃圾收集器不會從DOM元素中清除。但是如果這個引用在裏面附加到這個元素監聽器呢?GC清除會刪除其偵聽器中引用的元素變量嗎?
<span id="element">aga</span>
<script>
function attach() {
var element = document.getElementById("element");
element.addEventListener("click", function() {
//1) if element isn't used in this function
console.log('aga');
//2) if element is used in this function
console.log(element);
});
}
attach();
document.body.innerHTML = '';
</script>