JavaScript Intl.DisplayNames 構造函數用於創建 Intl.DisplayNames 對象。該構造函數是使用 new 關鍵字創建的。如果我們創建不帶 new 關鍵字的構造函數,它將給出 TypeError
用法:
new Intl.DisplayNames(loc, opt)
Parameters: 它有兩個參數都是可選的。
- loc: 它是一個字符串或字符串數組,允許以下值
- nu: 它指定要使用的編號係統,可以阿拉伯, 巴厘島, latn, tibt等等。
- opt: 它是一個可以具有以下屬性的對象樣式、類型、語言顯示、後備等等。
返回:一個 DisplayNames 對象。
下麵的示例說明了 JavaScript Intl DisplayNames() 構造函數:
例1:在此例如,我們使用 dateTimeField 和 calendar/等屬性
Javascript
const example1 = new Intl.DisplayNames("en", { type: "dateTimeField" });
const example2 = new Intl.DisplayNames("fr", { type: "dateTimeField" });
const example3 = new Intl.DisplayNames("en", {type: "calendar"});
console.log(example1.of("year"));
console.log(example2.of("year"));
console.log(example3.of("chinese"));
輸出:
year année Chinese Calendar
示例 2:在此示例中,我們將在構造函數中使用 Language 和 LanguageDisplay 等屬性。
Javascript
const example1 = new Intl.DisplayNames("en", {
type: "language",
languageDisplay: "dialect",
});
const example2 = new Intl.DisplayNames("fr", {
type: "language",
languageDisplay: "standard",
});
console.log(example1.of("en-GB"));
console.log(example2.of("en-GB"));
輸出:
British English anglais (Royaume-Uni)
支持的瀏覽器:
- Chrome
- Edge
- Firefox
- Opera
- Safari
我們有完整的 JavaScript Intl 方法列表可供檢查,請閱讀 JavaScript Intl Reference 文章。
相關用法
- JavaScript Intl DateTimeFormat()用法及代碼示例
- JavaScript Intl ListFormat()用法及代碼示例
- JavaScript Intl PluralRules()用法及代碼示例
- JavaScript Intl Collator()用法及代碼示例
- JavaScript Intl Segementer()用法及代碼示例
- JavaScript Intl.ListFormat.supportedLocalesOf()用法及代碼示例
- JavaScript Intl.DateTimeFormat.supportedLocalesOf()用法及代碼示例
- JavaScript Intl.Collator.supportedLocalesOf()用法及代碼示例
- JavaScript Math cosh()用法及代碼示例
- JavaScript Math sinh()用法及代碼示例
- JavaScript Math sin()用法及代碼示例
- JavaScript Math cos()用法及代碼示例
- JavaScript Math tan()用法及代碼示例
- JavaScript Math abs()用法及代碼示例
- JavaScript Math pow()用法及代碼示例
- JavaScript Math asin()用法及代碼示例
- JavaScript Math acos()用法及代碼示例
- JavaScript Math atan()用法及代碼示例
- JavaScript Math ceil()用法及代碼示例
- JavaScript Math floor()用法及代碼示例
- JavaScript Math round()用法及代碼示例
- JavaScript Math trunc()用法及代碼示例
- JavaScript Math max()用法及代碼示例
- JavaScript Math min()用法及代碼示例
- JavaScript Math sqrt()用法及代碼示例
注:本文由純淨天空篩選整理自shobhit_sharma大神的英文原創作品 JavaScript Intl DisplayNames() Constructor。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。