Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Run simple script

$
0
0
Hello xtracer!

If you have script code in a string, you can use the Evaluate() method to run it:
string code = @"
    function TestMethod(testObj) 
    { 
        //some action 
        return testObj; 
    }
";

engine.Evaluate(code);
The script code in this case defines a function called TestMethod. To execute that function, you can use additional scripts:
engine.Evaluate("TestMethod(123)");
engine.Evaluate("TestMethod({foo: 123, bar: 'abc'})");
Or, you can use the Script property to execute the function directly, without parsing or compiling additional scripts:
engine.Script.TestMethod(123);
Please let us know if you have additional questions.

Good luck!

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images