Intl.ListFormat.prototype.resolvedOptions()
resolvedOptions() 方法是 Intl.ListFormat 实例的一个方法,它返回一个新对象,其中包含在初始化此 ListFormat 对象期间计算的选项的属性。
试一试
const deListFormatter = new Intl.ListFormat("de-DE", { type: "disjunction" });
const options = deListFormatter.resolvedOptions();
console.log(options.locale);
// Expected output: "de-DE"
console.log(options.style);
// Expected output: "long"
console.log(options.type);
// Expected output: "disjunction"
语法
js
resolvedOptions()
参数
无。
返回值
一个新对象,其中包含在初始化此 ListFormat 对象期间计算的选项的属性。该对象具有以下属性,按列出顺序排列:
locale-
由 区域设置协商过程确定的实际使用的区域设置的 BCP 47 语言标记。输出中不包含 Unicode 扩展键。
type-
在
options参数中为此属性提供的值,并根据需要填充默认值。它可以是"conjunction"(连词)、"disjunction"(选择)或"unit"(单位)。默认值为"conjunction"。 style-
在
options参数中为此属性提供的值,并根据需要填充默认值。它可以是"long"(长)、"short"(短)或"narrow"(极短)。默认值为"long"。
示例
使用 resolvedOptions
js
const deListFormatter = new Intl.ListFormat("de-DE", { style: "short" });
const usedOptions = de.resolvedOptions();
console.log(usedOptions.locale); // "de-DE"
console.log(usedOptions.style); // "short"
console.log(usedOptions.type); // "conjunction" (the default value)
规范
| 规范 |
|---|
| ECMAScript® 2026 国际化 API 规范 # sec-Intl.ListFormat.prototype.resolvedoptions |
浏览器兼容性
加载中…