Intl.Segmenter.prototype.resolvedOptions()

Baseline 2024
新推出

自 ⁨2024 年 4 月⁩ 起,此功能可在最新的裝置和瀏覽器版本中執行。此功能可能不適用於較舊的裝置或瀏覽器。

resolvedOptions() 方法用於 Intl.Segmenter 例項,它返回一個新物件,其中包含在此 Segmenter 物件初始化期間計算出的選項屬性。

試一試

const segmenter = new Intl.Segmenter("fr-FR");
const options = segmenter.resolvedOptions();

console.log(options.locale);
// Expected output: "fr-FR"

console.log(options.granularity);
// Expected output: "grapheme"

語法

js
resolvedOptions()

引數

無。

返回值

返回一個新物件,其中包含此 Segmenter 物件初始化期間計算出的選項屬性。該物件具有以下屬性,按列出順序排列:

locale

區域設定協商過程確定的實際使用的區域設定的 BCP 47 語言標記。輸出中不包含 Unicode 擴充套件鍵。

granularity

options 引數中為此屬性提供的值,並根據需要填充預設值。它可以是 "grapheme""word""sentence"。預設值為 "grapheme"

示例

基本用法

js
const spanishSegmenter = new Intl.Segmenter("es", { granularity: "sentence" });
const options = spanishSegmenter.resolvedOptions();
console.log(options.locale); // "es"
console.log(options.granularity); // "sentence"

預設粒度

js
const spanishSegmenter = new Intl.Segmenter("es");
const options = spanishSegmenter.resolvedOptions();
console.log(options.locale); // "es"
console.log(options.granularity); // "grapheme"

備用區域設定

js
const banSegmenter = new Intl.Segmenter("ban");
const options = banSegmenter.resolvedOptions();
console.log(options.locale);
// "fr" on a runtime where the Balinese locale
// is not supported and French is the default locale
console.log(options.granularity); // "grapheme"

規範

規範
ECMAScript® 2026 國際化 API 規範
# sec-intl.segmenter.prototype.resolvedoptions

瀏覽器相容性