0
我在使用jooc包裝d3-force的子集時遇到了問題。該庫不使用對象屬性,而是實現融合的getter-setter函數,例如,包裝熔融吸氣劑功能
simulation.force("x", d3.forceX()) // setter
simulation.force("x") // getter
我想找到一種方法來模擬OCaml中的同一種多態性。這是我目前有
module Force = struct
class type force = object
(* not important *)
end
let x(): force Js.t = Js.Unsafe.meth_call __d3 "forceX" [||]
class type simulation = object
method force : string -> #force Js.t -> unit Js.meth
end
let simulation nodes: simulation Js.t =
Js.Unsafe.(meth_call __d3 "forceSimulation" [|inject nodes|])
end
而這裏的什麼我後
let s = Force.simulation nodes in begin
s##force "x" (Force.x())
s##force "x" (* wishful thinking *)
end
非常感謝,非常感謝! –