在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/HTML5  HTML/ JS 引起內(nèi)存泄漏問(wèn)題

JS 引起內(nèi)存泄漏問(wèn)題

代碼如下:

document.onload = (function() {
    var GraphCreator = function(name) {
        var thisGraph = this;
        console.log(thisGraph);
        this.name = name || '';
    };

    GraphCreator.prototype.setName = function(name) {
        var thisGraph = this;
        thisGraph.name = name;
    };

    GraphCreator.prototype.addTab = function(data) {
        var content = document.getElementById('content');
        var tab = juicer($('#extended_tpl').html(), data);
        content.append(tab);
    };

    window.GraphCreator = GraphCreator;

})();

var graph = new GraphCreator();
graph.setName('graph_one');

這樣寫(xiě)會(huì)引起內(nèi)存泄漏嗎?哪些地方是不合理的?

回答
編輯回答
離夢(mèng)

document.onload才對(duì)吧,而且后面應(yīng)該不是一個(gè)自執(zhí)行吧

要么(function())(),要么document.onload=function()

在外部庫(kù)引用正確的話,感覺(jué)沒(méi)什么問(wèn)題

2018年4月30日 07:03
編輯回答
怣人

閉包就是一個(gè)函數(shù)引用另外一個(gè)函數(shù)的變量,你確定你有閉包?

2017年6月19日 13:02