Intl.Segmenter.prototype.resolvedOptions()

Intl.Segmenter 实例的 resolvedOptions() 方法返回一个新对象,其属性反映了在此 Intl.Segmenter 对象初始化期间计算的区域设置和粒度选项。

¥The resolvedOptions() method of Intl.Segmenter instances returns a new object with properties reflecting the locale and granularity options computed during the initialization of this Intl.Segmenter object.

Try it

语法

¥Syntax

js
resolvedOptions()

参数

¥Parameters

没有任何。

¥None.

返回值

¥Return value

一个新对象,其属性反映在给定 Intl.Segmenter 对象初始化期间计算的区域设置和排序规则选项。

¥A new object with properties reflecting the locale and collation options computed during the initialization of the given Intl.Segmenter object.

描述

¥Description

生成的对象具有以下属性:

¥The resulting object has the following properties:

locale

实际使用的区域设置的 BCP 47 语言标记。如果在导致此区域设置的输入 BCP 47 语言标记中请求了任何 Unicode 扩展值,则此区域设置所请求和支持的键值对将包含在 locale 中。

granularity

options 参数中为此属性提供的值或作为默认值填写。

示例

¥Examples

基本用法

¥Basic usage

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

默认粒度

¥Default granularity

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

后备区域设置

¥Fallback locale

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"

规范

Specification
ECMAScript Internationalization API Specification
# sec-intl.segmenter.prototype.resolvedoptions

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility