1

我试图绑定的库的一部分返回一个对象 -

Editor.prototype.getHandlers = function() {
  return {
    'shape.append': require('./draw/AppendShapeHandler'),
    'shape.create': require('./draw/CreateShapeHandler')
  };
};

我不知道如何指定类类型,因为返回的对象是匿名的:

class type editor = object
  method getHandlers : ? Js.t Js.opt Js.meth
end

有人可以在这里提出前进的方向吗?

谢谢

缺口

4

1 回答 1

0

对于这种情况,可能类似于:

class type editor = object
  method getHandlers : <shape_append : Js.js_string Js.t Js.meth> Js.t Js.meth
end

更多示例:

class type server = object
  method listen : int -> (unit -> unit) Js.callback -> unit Js.meth
  method close : (unit -> unit) Js.callback -> unit Js.meth
  method address :
            <address: Js.js_string Js.t Js.readonly_prop;
             family : Js.js_string Js.t Js.readonly_prop;
             port: Js.js_string Js.t Js.readonly_prop> Js.t Js.meth
end

这种以这种方式绑定的方法是有效的,但正如我在 OCaml nodejs 绑定中了解到的那样,最好在更高级别编写而不是执行这些绑定。https://github.com/fxfactorial/ocaml-nodejs(查看早期的 git 历史以获取更多这样的示例)

于 2016-03-17T22:59:48.890 回答