Intl.ListFormat.prototype.resolvedOptions()

Baseline 已廣泛支援

此特性已得到良好支援,可在多種裝置和瀏覽器版本上使用。自 2021 年 4 月起,所有瀏覽器均已支援此特性。

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

瀏覽器相容性

另見