繁体   English   中英

如何将 f# fable 代码编译为多参数 javascript 函数

[英]How to compile f# fable code to a multiple parameter javascript function

嗨,我正在尝试为用 java 编写的数据库制作一些基本绑定,理想情况下我希望在 F# 中实际使用。 但是我对javascript相当陌生。 我设法使绑定与 1 个参数一起工作,但是由于在需要 3 个参数时尝试调用具有 1 个参数的函数,因此多个参数使程序崩溃。

编码:

type IRNCouchDBs =
    abstract member Add : string*string*((string)->string)

[<Import("CouchDB", from = "NativeModules")>]
let couchDB : IRNCouchDBs = jsNative

添加在这种情况下是在 java 中,本质上是:

@ReactMethod 
public void Add (String name, String type, Callback cb)

如果我像这样调用 f# 代码

 let str (s : string)  =  s //just a test function
couchDB.Add ("name", "type", (str "test"))

然后发生错误,它抱怨我试图将一个 1 参数函数传递给一个多参数函数。

任何如何解决这个问题的想法将不胜感激。

我想通了,回想起来相当明显。

type IRNCouchDBs =
    abstract member Add : Func<string, string, ((string*string->string)), unit>

[<Import("CouchDB", from = "NativeModules")>]
let couchDB : IRNCouchDBs = jsNative


let f' = (fun (x :string,y ) -> (x + y))
couchDB.Add.Invoke (fish.FishType,fish.Name, f')

使用 Func,并调用它,这似乎是这样做的方法。

暂无
暂无

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

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