How to clear the JS? of the previous page in H5 single page application

has been trying to make a single-page application recently, written in native JS, without any other framework.
after changing the page with the HistoryAPI of H5, the JS of the previous page is still working. For example, only the A page has:
< script id= "pager" >
var vm= {
.
};
var bm = {
.
.
};
< / script >
jumps to the B page, vm still exists in memory, and now the more troublesome way is vm= {} to empty. But feel that this method is unorthodox, accidentally will be left out, is there a more convenient way to remove all the JS on the previous page? (do not apply framework)

Mar.15,2022

are all single-page applications, where is the previous page?


global variable? Come on!
now your idea is not to use frameworks, and you also want to pursue more "orthodox" programming, so I'll at least tell you that you should use object-oriented programming, without global variables, and encapsulate them into attributes.
if you don't want to use object-oriented programming, vm= {} is certainly an orthodox programming method, if you're sure it's really necessary to clear the object. In fact, at this point, you can write whatever you want. anyway, you have hardly followed any norms, so there is no need to pursue orthodoxy.

Menu