Forums > Javascript

sticky variables

August 24, 2006 | 11:17 pm

consider the following code:

autowatch = 1;
var test = 10;

function printtest()
{
post(test);
}

if you delete the variable test at one point and resave the textfile, you
can still reference "test" and it will still return 10. Is it intended like
this? I find it really confusing sometimes, because if you make a mistake
like this, you won’t notice until you restart max.

-thijs


August 25, 2006 | 6:24 am

On Aug 24, 2006, at 4:17 PM, Thijs Koerselman wrote:

> consider the following code:
>
> autowatch = 1;
> var test = 10;
>
> function printtest()
> {
> post(test);
> }
>
> if you delete the variable test at one point and resave the
> textfile, you can still reference "test" and it will still return
> 10. Is it intended like this? I find it really confusing sometimes,
> because if you make a mistake like this, you won’t notice until you
> restart max.

Only function properties are explicitly deleted on re-compile of a
javascript file. If you close your patch and re-open all properties
are created in a fresh script. This is intended behavior.

-Joshua


August 25, 2006 | 8:56 am

On 8/25/06, Joshua Kit Clayton wrote:
>
>
>
> Only function properties are explicitly deleted on re-compile of a
> javascript file. If you close your patch and re-open all properties
> are created in a fresh script. This is intended behavior.

ok thanks. I think I’ll just make it a habit to declare variables as
function properties then.

best, -thijs


Viewing 3 posts - 1 through 3 (of 3 total)