我的標籤列表:OCaml的動態函數名
let tags = ["div", "h1", "p"]
我可以生成包含這些標籤的名稱功能模塊?
/*不介意的語法,這是Facebook的原因(新接口ocaml的)*/
let module DOM = {
let div props children => Js.Unsafe.fun_call
(Js.Unsafe.get dom (Js.string "div")) [|Js.Unsafe.inject props, Js.Unsafe.inject children|];
let h1 props children => Js.Unsafe.fun_call
(Js.Unsafe.get dom (Js.string "h1")) [|Js.Unsafe.inject props, Js.Unsafe.inject children|];
let p props children => Js.Unsafe.fun_call
(Js.Unsafe.get dom (Js.string "p")) [|Js.Unsafe.inject props, Js.Unsafe.inject children|];
}
標籤名稱應該成爲模塊中的功能... 這可能嗎?
這是一個問題的切線,但你是否知道[tyxml](https://ocsigen.org/tyxml/manual/)(和相關的[js_of_ocaml接口](https://ocsigen.org) /js_of_ocaml/2.7/api/Tyxml_js))? – Drup
不,我不是。我會看看它。感謝你! – Seneca
但是,您可以生成映射或散列表,將字符串映射到函數。 – ivg