我试图在Fsharp写一个防暴标签,但是如果不改变骚乱就无法这样做 .

在JavaScript中我应该provide a function like

function(opts) {
  this.on("update",function(opts){
    this.opts = opts || this.opts;
  });
}

然后使用Function.prototype.call进行骚乱call this function

if (impl.fn) { impl.fn.call(this, opts); }

在F#中,我尝试了以下方法:

[<Emit("this")>]
let isThis (x: 'a) : obj = jsNative

let bind fn =
  fun o ->
    fn (isThis 1) o 

[<Emit("$0 === undefined")>]
let isUndefined (x: 'a) : bool = jsNative

bind
  (
    fun me opts ->
      me?on(
        "update"
        ,(
          fun opts ->
            if not (isUndefined opts) then
              me?opts <- opts
              ()
        )
      )
  )

然而; bind函数被转换为:

export function bind(fn, o) {
  return fn(this)(o);
}

我想要咖喱时不要晃动,我想要的输出是:

export function bind(fn) {
  return function(o){
    return fn(this)(o);
  }
}

我能让这个工作的唯一方法是将riot.js改为:

if (impl.fn) { impl.fn(this)(opts); }

并通过以下方式在F#中提供我的功能:

fun me opts ->
  me?on(
    "update"
    ,(
      fun opts ->
        if not (isUndefined opts) then
          me?opts <- opts
          ()
    )
  )

更改第三方库以满足转换器生成的代码并不理想 . 有没有办法让转换器生成我正在寻找的输出?

[update]

不需要更改第三方代码的更好方法是将绑定功能作为第三方JavaScript提供:

然后导入它并在模板代码文件中使用bind:

let JSI = 
  bind<(obj -> obj -> unit) -> obj>
    "../../../js/3rd/JSI.js"
bind
  (
    fun me opts ->
      me?on(
        "update"
        ,(
          fun opts ->
            if not (isUndefined opts) then
              me?opts <- opts
              ()
        )
      )
  )