[RESOLVED] problem when compiling ECMA scripts with VSA JScript engine
A part of my current project has to do with running JScripts from .NET. For this I create a VSA Jscript engine, feed it with the scripts, compile and run.
The problem comes when compiling: all names used in functions and not declared as "var" raise errors. Clearly, no run is possible anymore.
I could not find any reference to this syntax requirement.
Is this really an error, for JScript.net? If not, is there any way to "tell" the JScript engine not to treat this as an error?
It would be nice to have definitive answeres to these questions, before writing a translator for javascript code...
[633 byte] By [
petru66] at [2007-11-20 11:07:02]

# 1 Re: [RESOLVED] problem when compiling ECMA scripts with VSA JScript engine
In all variations of JavaScript, variables are not required to be declared. Are you using some form of Option Explicit?
# 2 Re: [RESOLVED] problem when compiling ECMA scripts with VSA JScript engine
Oh, but they are required to be declared... :(
I've just discovered (so I must apologize for posting before a thorough documentation) the following:
"You can declare a variable without using the var keyword in the declaration and assign a value to it. This is known as an implicit declaration and it is not recommended.
An implicit declaration creates a property of the global object with the assigned name; the property behaves like a variable with global scope visibility.
When you declare a variable at the procedure level, though, you typically do not want it to be visible at the global scope. In this case, you must use the var keyword in your variable declaration."
The documentation explains, further, how to compile JScript code without "var":
"To compile a program from the command line that does not use the var keyword, you must turn off the fast option by using /fast-."
And, well, it works. So far.
Thanks for the answer. Hopefully this little thread will help other people as well.