简体   繁体   English

使用复杂参数执行功能

[英]Execute function with complex parameters

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. 由于这个问题的不相关原因,我需要从.net桌面应用程序调用js文件中定义的javascript函数,并获取结果。

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 我有这个js文件

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

Then, for call this function on .net, i use this code: 然后,为了在.net上调用此函数,我使用以下代码:

    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 此时suma =5。但是,如果plus函数的定义是

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

How should i call plus function to get the same result? 我应该如何调用plus函数来获得相同的结果?

you are calling value property of a and b means a and b are objects. 您正在调用ab value属性,表示a和b是对象。 so you can call that function as 因此您可以将该函数称为

Dim suma As Integer = aux.Evaluate("plus({value:2},{value:3})")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM