P
petermichaux
Hi,
I've wondered for a what the differences between the following.
<script type="text/javascript">
var foo = 10;
</script>
<script type="text/javascript">
window.foo = 10;
</script>
For one, I think I can do
delete window.foo;
The reason I ask is avoiding garbage collection. If I have an event
handler function for onload that declares some global object that I
want to persist I would like to avoid doing this in the head element.
<script type="text/javascript">
var foo;
function handleLoad(e) {
foo = {bar: 45};
};
</script>
I would rather have just the following if it will serve my needs as it
seems more self contained
<script type="text/javascript">
function handleLoad(e) {
window.foo = {bar: 45};
};
</script>
Thank you,
Peter
I've wondered for a what the differences between the following.
<script type="text/javascript">
var foo = 10;
</script>
<script type="text/javascript">
window.foo = 10;
</script>
For one, I think I can do
delete window.foo;
The reason I ask is avoiding garbage collection. If I have an event
handler function for onload that declares some global object that I
want to persist I would like to avoid doing this in the head element.
<script type="text/javascript">
var foo;
function handleLoad(e) {
foo = {bar: 45};
};
</script>
I would rather have just the following if it will serve my needs as it
seems more self contained
<script type="text/javascript">
function handleLoad(e) {
window.foo = {bar: 45};
};
</script>
Thank you,
Peter