[英]Memory management in javascript
I am trying to develop an application using javascript and to help organise my code, I am coding using objects. 我正在尝试使用javascript开发应用程序并帮助组织我的代码,我正在使用对象进行编码。 However, I don't really understand how the javascript engine is managing my object.
但是,我真的不明白javascript引擎是如何管理我的对象的。
If in a first HTML page1
where I include a js file, I make an object obj1
when I switch to HTML page2
where I include both the old js script (already included in the first html page ) and the second js file where I want to use that object created in the first javascript file, it's undefined
. 如果在我包含js文件的第一个HTML
page1
中,当我切换到HTML page2
时我创建了一个对象obj1
,其中我包括旧的js脚本(已包含在第一个html页面中)和第二个js文件,我想要使用在第一个javascript文件中创建的对象,它是undefined
。
Can anyone help me understand how javascript manages objects and how, going from page to page, to get my object ? 任何人都可以帮助我理解javascript如何管理对象以及如何从一个页面到另一个页面来获取我的对象?
When you load a new page (or even reload the current one), everything that was on the page you are leaving is destroyed . 当您加载新页面(甚至重新加载当前页面)时,您要离开的页面上的所有内容都将被销毁 。
If you want to make an object persistent, consider using localStorage
to save the information you need. 如果要使对象持久化,请考虑使用
localStorage
来保存所需的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.