Exposing Javascript functions to the CLR
Calling Javascript functions from the CLR
Is you need to explicitly execute a Javascript function from your application, you can use the
Call() method.
JintEngine jint = new JintEngine();
jint .Run(@"
var f = function (x, y) {
return x * y;
}
";
Console.WriteLine(jint.CallFunction("f", 2, 3)); // Displays 6
Using Javascript functions as delegate
In the example below, a script is using a generic list and converts every element to is square value. The transformation is coded inside a Javascript function.
var list = new System.Collections.Generic.List{System.Int32}();
list.Add(7); list.Add(3); list.Add(4);
list = list.ConvertAll{System.Double}( function (x) { return x * x; });
assert(3, Number(list.Count));
assert(49, list[0]);
assert(9, list[1]);
assert(16, list[2]);