使用try finally很容易解決些問題 復制代碼 代碼如下:function createButton(){ var obj = document.createElement("button"); " /> 日韩成人精品一区二区,精品国产一区二区三区噜噜噜,国产中文字幕视频

四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

try finally 妙用,防止內存泄漏


[Ctrl+A 全選 注:如需引入外部Js需刷新才能執行]
這種寫法在IE中100%內存泄漏

使用try finally很容易解決些問題
復制代碼 代碼如下:
function createButton(){ 
 var obj = document.createElement("button"); 
 obj.innerHTML="點我!"; 
 obj.onclick=function(){ 
 //處理click事件 
 } 
 obj.onmouseover=function(){ 
 //處理mouseover事件 
 } 
 try{ 
 return obj; 
 }finally{ 
 obj = null;//這句話在return 之后才執行,有效地解決了需在return后將obj置null的問題 
 } 



一個函數或方法中,其實有很多地方都需要這種選返回值,最后執行某些事的

=====================================================================
附一:JavaScript Error (try/catch/finally)
Introduction
Like other programming languages, JavaScript provides the possibility to make use of 
the try/catch/finally block. Usually when an error is encountered then the script stops and doesn't
 continue with the rest of the page. The try/catch/finally block can be used to continue the 
processing with the rest of the page. You just have to put the code in your try block and when 
an error in encountered there, then it will call the catch block. The finally block is called always 
regardless of an error occurred or not. The following example makes the usage clear.

Example: 

[Ctrl+A 全選 注:如需引入外部Js需刷新才能執行]

JavaScript技術try finally 妙用,防止內存泄漏,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 小城故事多歌曲原唱| 安泽豪个人资料| julia taylor| 亚洲1区| 极品少妇啪啪久久蜜臀| 董明珠:简历 个人资料| 小野寺律| soul电影| 关德兴| 蝴蝶视频在线观看| 我的碧可动画| 入党培养考察情况范文| 在线观看三级视频| 轨迹地图| 金装维尔梅| land of the lost| 视频www| 姐妹在线| 爱爱内含光电视剧结局在线观看| 敬天法祖| 暗夜幕后在线观看完整版| 漂亮主妇| 4480午夜| 赖丹丹| 北京宝哥打小混混视频| 木村多江| 03s402| 定型枕什么时候能给宝宝用| 网络谜踪2 电影| 今天是你的生日bb伴奏正谱| 糟老头视频| 正在行动| 白宝山电视剧26集免费观看| 电影白上之黑| 扎西顿珠的个人资料简介 | 免费成人视屏| 顺风| 李采禫的电影| 韩国电影陈诗雅主演| 深圳古镇| 大地免费在线观看|