【发布时间】:2019-07-15 03:35:27
【问题描述】:
tl;dr:如何更改以下绑定以能够写入Intl.DateTimeFormat.make() 而不是Intl_.DateTimeFormat.make()?
type dateTimeFormat;
[@bs.deriving abstract]
type formatOptions = {
[@bs.optional]
weekday: string,
[@bs.optional]
day: string,
[@bs.optional]
month: string,
};
module Intl_ {
module DateTimeFormat {
module Impl {
type t;
};
[@bs.new] external make: unit => Impl.t = "Intl.DateTimeFormat";
[@bs.send] external format: (Impl.t, Js.Date.t) => string = "";
};
}
Intl_.DateTimeFormat.make()
->Intl_.DateTimeFormat.format(Js.Date.make())
->Js.log;
问题
没有下划线,这将编译为:
var Impl = /* module */[];
var DateTimeFormat = /* module */[/* Impl */Impl];
var Intl = /* module */[/* DateTimeFormat */DateTimeFormat];
console.log(new Intl.DateTimeFormat().format(new Date()));
exports.Intl = Intl;
问题是var Intl = ... 遮蔽了全局Intl,从而破坏了new Intl.DateTimeFormat()。
【问题讨论】:
标签: javascript binding ffi reason bucklescript