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]);

Last edited Feb 8, 2010 at 12:36 PM by sebastienros, version 2


chauhanyogi Jun 8, 2016 at 10:25 AM 
i m younger to use this dll so i am not gettin JintEngine class in my file.can be help me any one?.

CarbonMan Dec 10, 2012 at 9:47 AM 
@artyprog I think you are looking at this from the wrong view. All that code is meant to run AS Javascript. The {..} is interpreted by the Jint engine which converts it to <..>
I was also confused with it. The problem with the example is that it does not show the code assigned to a string and passed to the Jint engine.

artyprog Feb 6, 2012 at 7:47 AM 
list = list.ConvertAll<System.Double>( function (x) { return x * x; });

artyprog Feb 6, 2012 at 7:46 AM 
A little typo :-)
var list = new System.Collections.Generic.List<System.Int32>();

tom_peres Apr 6, 2010 at 3:49 PM 
I'm really trying to find the way to use this method.
But... i can't use them. Can you help me?