第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

關于JS的內存泄漏跟JS代碼的規(guī)范問題大家是怎么處理的?

關于JS的內存泄漏跟JS代碼的規(guī)范問題大家是怎么處理的?

HUX布斯 2018-12-07 12:19:31
關于JS的內存泄漏跟JS代碼的規(guī)范問題大家是怎么處理的? 比如這篇文章(JavaScript 中的內存泄露模式)中提到為防止內存泄露,把代碼寫成這樣: 方法一: <html> <body> <script type="text/javascript"> document.write("Avoiding a memory leak by adding another closure"); window.onload=function outerFunction(){ var anotherObj =function innerFunction() { // Some logic here alert("Hi! I have avoided the leak"); }; (function anotherInnerFunction(){ var obj = document.getElementById("element"); obj.onclick=anotherObj })(); }; </script> <button id="element">"Click Here"</button> </body> </html> 方法二: <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 here alert("Hi! I have avoided the leak"); } </script> </head> <body> <button id="element">"Click Here"</button> </body> </html> 方法一的代碼明顯比較亂,方法二很多人的寫法都是寫成匿名方法(方法表達式)的形式。 請問在JS的內存泄漏跟JS代碼的規(guī)范間大家是怎么平衡的呢?
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 418 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號