You can define variables that exist in the namespace of the pre-processor and which can then be used as if they were directives that you had created. For example, you might test some complex set of conditions and set a variable so that you can simply test for its existence later. Or you might use that variable in some fragment of code as a manifest constant, perhaps to specify the size of an array or a flag to activate some capability.
You should note that these pre-processor directives will likely not survive from one script block to another or for any duration in the time domain. They are not variables in the sense of a script variable.
To create a new pre-processor variable, use the @set directive, name the variable and assign a value to it, like this:
@set @myvariable=1000
You can then use the variable in the source text like this:
document.write(@myvariable);
You may need to experiment to establish how long one of these variables actually persists. It is unlikely to still be defined when an event handler is called. However, that event handler may have been interpreted and stored when the script was loaded, in which case the variable would have been replaced by its value at that time.
If you intend to hide this directive inside some comments, it must be done like this:
/*@set @myvariable=1000 @*/
See also: | Pre-processing, Pre-processing - /*@ ... @*/ |
Prev | Home | Next |
Pre-processing - @if( ... ) ... | Up | Precedence |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |