How to unload a javascript from an html?

前端 未结 7 2125
予麋鹿
予麋鹿 2020-11-28 10:27

How can I unload a JavaScript resource with all its defined objects from the DOM?

Im developing a simple framework that enables to load html fragments into a \"main\

7条回答
  •  天命终不由人
    2020-11-28 10:59

    If you need to unload a specific object, it's fairly easy: just set it to {}

    ie: myobj = {};

    So if you know what objects are created in a particular include, it won't be hard at all.

    On the other hand, if you don't know what objects are created in a particular include, there isn't a mechansim to find out - you can't ask Javascript to tell you what was defined in a particular include.

    However, I would say that if you don't know what objects are being loaded in a particular javascript file, you're probably not doing yourself any favours in loading it (you should always have a reasonable idea what code does in your site), or in trying to unload it manually (if you don't know what it does, that implies its a third party include, which means that unsetting it manually is likely to break things).

提交回复
热议问题