Intl.Segmenter.prototype.resolvedOptions()
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 |
浏览器兼容性
加载中…