sticky variables

Aug 24, 2006 at 11:17pm

sticky variables

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

#27286
Aug 25, 2006 at 6:24am

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

#82411
Aug 25, 2006 at 8:56am

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

#82412

You must be logged in to reply to this topic.