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?

walther
  • 13,466
  • 5
  • 41
  • 67
Rumpelstinsk
  • 3,107
  • 3
  • 30
  • 57

1 Answers1

1

you are calling value property of a and b means a and b are objects. so you can call that function as

Dim suma As Integer = aux.Evaluate("plus({value:2},{value:3})")
Laxmikant Dange
  • 7,606
  • 6
  • 40
  • 65