使用时,最好不要使用闭包,可以将函数声明后,直接调用函数名即可。
<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>