您的位置:首页 > Web前端 > JavaScript

javascript闭包产生的内存泄漏

2011-09-03 12:09 435 查看
使用时,最好不要使用闭包,可以将函数声明后,直接调用函数名即可。

<html><head><script type="text/javascript">document.write("Avoid leaks by avoiding closures!");window.onload=function(){var obj = document.getElementById("element");obj.onclick = doesNotLeak;}function doesNotLeak(){//Your Logic herealert("Hi!
I have avoided the leak");}</script></head><body><button id="element">"Click Here"</button></body></html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息