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

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

代碼如下:

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');

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

回答
編輯回答
離夢

document.onload才對吧,而且后面應該不是一個自執(zhí)行吧

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

在外部庫引用正確的話,感覺沒什么問題

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

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

2017年6月19日 13:02