-
Notifications
You must be signed in to change notification settings - Fork 127
Executing a script
paulbartrum edited this page Dec 14, 2015
·
2 revisions
Executing a script runs a script from start to finish. For example, to execute the script at "c:\test.js" use the following code:
var engine = new Jurassic.ScriptEngine();
engine.ExecuteFile(@"c:\test.js");
If you have the code to run in a string, use the Execute()
method:
var engine = new Jurassic.ScriptEngine();
engine.Execute("console.log('testing')");
Note: executing a script is different from evaluating it in the following ways:
-
Evaluate()
returns a value andExecute()
does not. -
Execute()
runs slightly faster. - Variables declared inside
Evaluate()
can be deleted whereas variables declared inside Execute() cannot.
The specification uses the terms "global code" and "eval code" to describe these differences.
Next tutorial: Accessing and modifying global variables