當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
javascript闭包产生的内存泄漏
生活随笔
收集整理的這篇文章主要介紹了
javascript闭包产生的内存泄漏
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
使用時,最好不要使用閉包,可以將函數聲明后,直接調用函數名即可。
<html><head><script type="text/javascript">document.write("Avoid leaks by avoiding closures!");window.οnlοad=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>
總結
以上是生活随笔為你收集整理的javascript闭包产生的内存泄漏的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 但有很多的HTML5朋友
- 下一篇: js库prototype中的$()