Stop javascript execution

When I run my javascript script file in windows command line environment and free text appears after my code. How can I stop the javascript interpreter from running? For instance:

var fso = new ActiveXObject("Scripting.FileSystemObject");
delete fso;
exit(); // some kind of WORKING exit command
Hungry lazy frog ate a big brown fox.

      

+2


a source to share


3 answers


There is nothing that can be done to stop the interpreter before the compiler sees a specific line, because the entire Javascript source file is first compiled to bytecode, and it is bytecode that is not interpreted in your source code.

What you could do (although it would still be messy) would be to put some free text in a comment at the end of the file. Then you can open the original file and read it from the rest of the code. It still cannot be completely free text, although it must be a valid comment



/*
 whatever text you want provided it doesn't contain * followed immediately by /
 */

      

It's much better to just admit defeat and store whatever data you need in a separate file.

+2


a source


If you surround it with quotes, it will be interpreted / compiled but has no effect, like



var fso = new ActiveXObject("Scripting.FileSystemObject");
delete fso;
exit(); // some kind of WORKING exit command
"Hungry lazy frog ate a big brown fox.";

      

+2


a source


Even if you exit, you will still have a problem because the entire script block must be parsed before the first statement is executed. With any dummy content after the exit command, the script would not be able to parse at all, even if that code was never reached.

If the free text was one line, you can get away with a trailing one //

. However does not work for multi-line comments as you will need to close */

. Ditto for conditional comments requiring /*@end @*/

.

+1


a source







All Articles