删除脚本元素是否会从内存中删除其功能? [英] Does removing a script element remove its functions from memory?

查看:46
本文介绍了删除脚本元素是否会从内存中删除其功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var scripts  = document.getElementsByTagName("script");
for (var i=scripts.length; i--; ){
   (scripts[i]).parentNode.removeChild(scripts[i]);
}

有人问我这个问题,我的第一个想法是:不.但是,当您删除 style 元素时,页面会自动更新,从而删除样式.这可能是由于浏览器如何钩住CSS-我想我记得CSS会在每个事件(鼠标移动,点击,类型等)上更新.

Someone asked me this question and my first thought was: no. However, when you remove the style elements, the page automatically updates, removing the styling. This could be because of how the browser hooks css - I think I recall that CSS updates on every event (mouse movement, clicks, type, etc).

我只是想确认一下,摆脱脚本标签并不会摆脱已经创建的功能,因为我不在可以测试的计算机上.

I just wanted to confirm, that getting rid of the script tag, won't get rid of the function that was already created, since I'm not at a computer where I can test.

这也让我想到了好的做法,可以帮助保护针对Firebug [-]类用户的代码

推荐答案

简短答案,不.

引擎对脚本进行一次评估的所有脚本都将保留在内存中,供您剩余的会话使用.即使删除整个包含代码的脚本节点也不会改变这一事实.

Any script which got evaluated once by the engine will stay in memory for the rest of your session. Even by removing the entire script node where the code was contained doesn't change that fact.

这篇关于删除脚本元素是否会从内存中删除其功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆