Unexpected line terminator in string literal.

Apr 29, 2013 at 7:20 PM
I'm trying to use Jurassic to store a simple JavaScript variable. When doing this:
var script = @"
    function Hello() {
    }";
var engine = new ScriptEngine();
engine.Execute("var script = '" + script + "';");
fails with the following error:

Unexpected line terminator in string literal.

I figured out myself that the newline in my script variable some how isn't treated like I expect it in Jurassic, but how do I fix it?
Coordinator
Apr 30, 2013 at 1:15 AM
String literals cannot contain newlines in javascript. The easiest way to do what you want is this:
var script = @"
    function Hello() {
    }";
var engine = new ScriptEngine();
engine.SetGlobalValue("script", script);
May 1, 2013 at 7:19 PM
Exactly what I was looking for. Thanks!