Patient Guy wrote:
Has anyone found it possible---that is, come up with a "trick"----to
specify IN THE SAME SCOPE 'const' for non-reassignable variables, with the
use of 'var' as a fallback should the interpreter respond with an error
upon seeing 'const'?
This is not the problem of the *execution* - it is the problem of
*pre-processing* when the source code is being parsed and broken on
tokens.
While you have plenty of control during the execution like
if(document.someMethod) etc. there is nothing you can do with
pre-processing *from within the script itself* : an absolute shiny
none. I'm saying it in case if you're currently trying to find some
"hack".
An absolute shiny none because pre-processing errors will happen
*before* the execution - thus before your script will become.
The only possibility (as in all other languages) is to use
pre-processor commands. Unfortunately up do date IE is the only browser
with an open interface pre-processor. All others still prefer to sit on
the cloud.
<script type="text/javascript">
/*@cc_on
@if (@_jscript_version >= 7)
/* JScript.Net with const support */
const foo = 'bar';
@elif (@_jscript)
/* some JScript but not JScript.Net */
var foo = 'bar';
@else @*/
/* Non-IE browser: act on your own risk */
// ?
/*@end @*/
</script>