Javascript why wrap a variable or constructor in an IIFE?

后端 未结 3 1419
梦毁少年i
梦毁少年i 2020-12-06 07:05

I saw something like this today

var Visualizer = (function() {
    function Visualizer() {
    //...
    }
    Visualizer.prototype.function1 = function () {         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-06 07:49

    In case there will be a lot of Visualizers, function1 will be same instance in all of them. As discussed here IIFE method leaks.

提交回复
热议问题