I'm currently working on a new feature that requires the execution of user-defined, anonymous JavaScript functions retrieved from a database on the server side within an ASP.Net application environment.
For this purpose, I am exploring the use of Jint (latest version from NuGet). So far, I have successfully executed functions that perform basic operations and return values without any issues, as shown below:
public void Do()
{
var jint = new Engine();
var add = jint.Execute(@"var f = " + GetJsFunction()).GetValue("f");
var value = add.Invoke(5, 4);
Console.Write("Result: " + value);
}
private string GetJsFunction()
{
return "function (x,y) {" +
" return x+y;" +
"}";
}
My main query is whether Jint supports the execution of JavaScript functions that utilize third-party libraries such as lodash. If so, how can I integrate the Jint engine with these third-party libraries?
As an illustration, consider the execution of the following JavaScript function:
private string GetFunction()
{
return "function (valueJson) { " +
" var value = JSON.parse(valueJson);" +
" var poi = _.find(value,{'Name' : 'Mike'});" +
" return poi; " +
"}";
}
Thank you in advance for your assistance.