javascript - 如何将 f# fable 代码编译为多参数 javascript 函数
问题描述
嗨,我正在尝试为用 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,并调用了它,这似乎是这样做的方法。
推荐阅读
- php - Why is 02000 evaluated to 1024
- xamarin.forms - Prism 模板包添加对 mono android 8.1 的引用但我做到了,但我仍然在抱怨
- sensenet - 如何使用 SenseNet dotnet 客户端在文件上传后更新自定义字段
- android - 当我的 Android 应用程序处于前台时,我想隐藏其他应用程序的所有通知。这可能吗?如何?
- java - 按自定义顺序对 Arraylist 进行排序
- javascript - 如何通过javascript从跨度中获取价值?
- amazon-s3 - 在 ec2 机器上安装 s3 存储桶作为网络驱动器
- php - 如何覆盖 Laravel 5.6 的默认登录机制?
- java - 如何在 JOOQ 中编写多字段“in”谓词?
- android - 如何在 Fragments 中使用 onBackPressed 方法