1

For a not relevant reason for this question, i need to call a javascript function, defined inside a js file, from a .net desktop application and get the result.

I'm using Jurassic to do this. However i don't know how to call functions which recieve complex types. Is more simple to explain using an example.

I have this js file

function plus(a, b) {
    return a + b;
}

Then, for call this function on .net, i use this code:

    Dim auxfile As New Jurassic.FileScriptSource(pathToPreviosJSFile)
    Dim aux As New Jurassic.ScriptEngine
    aux.Evaluate(auxfile)
    Dim suma As Integer = aux.Evaluate("plus(2,3)")

At this point suma = 5. However if the definition of plus function was

function plus(a, b) {
    return a.value + b.value;
}

How should i call plus function to get the same result?

4

1 回答 1

1

您正在调用 value 属性,a并且b意味着 a 和 b 是对象。所以你可以将该函数称为

Dim suma As Integer = aux.Evaluate("plus({value:2},{value:3})")
于 2015-05-28T09:19:28.860 回答