JS 引起内存泄漏问题

代码如下:

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

这样写会引起内存泄漏吗?哪些地方是不合理的?

阅读 2.4k
2 个回答

document.onload才对吧,而且后面应该不是一个自执行吧

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

在外部库引用正确的话,感觉没什么问题

闭包就是一个函数引用另外一个函数的变量,你确定你有闭包?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题