Unload files loaded with getScript?

后端 未结 5 1655
醉酒成梦
醉酒成梦 2020-12-10 06:57

With $.getScript I can load js files on the fly. Is it possible to \"unload\" some of these files ?

I have a ajax-based administrative panel. I have 3 sections. When

5条回答
  •  自闭症患者
    2020-12-10 07:27

    What I would do in this case would be to make all your JavaScript code part of an object structure then simply set the object to null once done with it.

    var myObj = {
        "property1": true,
        "property2": "Hello my name is Sam.",
        "mynamedfunction": function(){
           //do stuff
        },
        "othernamedfunction": function(){
           //do other stuff
        }
    };
    

    Once done set myObj=null;

    So rather than loading and unloading a file you are loading and unloading an object as needed! So you would load the file containing the object in, but then set the object to null once done with it, you can even load it in again after destroying it this way.

提交回复
热议问题