private static void FunctionCall() { dynamic jsContext = new DynamicJavascriptContext(new JavascriptContext()); string script = @" var F2 = function(pInt,pDouble,pString,pBool,pDate) { var s = ''+pInt+'-'+pDouble+'-'+pString+'-'+pBool+'-'+pDate; console.log(s); return 'F2'; }; "; jsContext.Run(script); var result = jsContext.Call("F2", 1, 123.456, "hello", true, DateTime.Now); }
public void CallingFunctions() { dynamic jsContext = new DynamicJavascriptContext(new JavascriptContext()); DateTime refDate = new DateTime(1964, 12, 11, 01, 02, 03); string script = @" var O2 = { F2: function(pInt,pDouble,pString,pBool,pDate) { return ''+this.Internal+'-'+pInt+'-'+pDouble+'-'+pString+'-'+pBool+'-'+formatDateUS(pDate); }, Internal:1 } "; jsContext.Load("format", Assembly.GetExecutingAssembly()); jsContext.Run(script); var expectedF2 = "1-1-123.456-hello-true-12/11/1964 1:2:3"; var f2Result = jsContext.Call("O2.F2", 1, 123.456, "hello", true, refDate); Assert.AreEqual(expectedF2, f2Result); }