You need a javascript interpreter if you want to execute javascript code. The C#s dynamic keyword is pretty useless in this aspect. You may take a look at Javascript .NET or Jint if you are trying to execute those functions in .NET code.
Here's an example with Jint:
using System;
using Jint;
class Program
{
static void Main()
{
var script = @"
function Add(a, b) {
return a + b;
}
function Substract(a, b) {
return a - b;
}
return Add(a, b);
";
var result = new JintEngine()
.SetParameter("a", 3)
.SetParameter("b", 5)
.Run(script);
Console.WriteLine("result: {0}", result);
}
}
Remark: what you have is not valid javascript. The var keyword cannot be used before function parameters. So you probably should start by fixing your code.
dynamickeyword is pretty useless in this aspect.WebBrowserinstance to return a javascriptCalculatorobject and usesdynamicto call it or a winforms implementation interchangeably. Actually rather cool.