From 01b0e12ba27b5069248fd09235e9a7143915ee30 Mon Sep 17 00:00:00 2001 From: Irvin Date: Wed, 16 Feb 2022 02:02:49 +0800 Subject: remove `notranslate` class in zh-CN --- .../reference/global_objects/string/localecompare/index.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'files/zh-cn/web/javascript/reference/global_objects/string/localecompare') diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/localecompare/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/localecompare/index.html index 1bdd45c95e..bf0e8ad0fb 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/localecompare/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/localecompare/index.html @@ -19,7 +19,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/localeCompare

语法

-
referenceStr.localeCompare(compareString[, locales[, options]])
+
referenceStr.localeCompare(compareString[, locales[, options]])

参数

@@ -90,7 +90,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/localeCompare

使用 localeCompare()

-
// The letter "a" is before "c" yielding a negative value
+
// The letter "a" is before "c" yielding a negative value
 'a'.localeCompare('c');
 // -2 or -1 (or some other negative value)
 
@@ -107,7 +107,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/localeCompare
 
 

locales 和 options 参数还没有被所有浏览器所支持。检查是否被支持, 使用 "i" 参数 (a requirement that illegal language tags are rejected) 判断是否有异常 {{jsxref("RangeError")}}抛出:

-
function localeCompareSupportsLocales() {
+
function localeCompareSupportsLocales() {
   try {
     'foo'.localeCompare​('bar', 'i');
   } catch (e) {
@@ -121,7 +121,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/localeCompare
 
 

在不同的语言下 localeCompare() 所提供的结果是不一致的。 为了能让用户得到正确的比较值, 通过使用 locales 参数来提供要比较的语言 (and possibly some fallback languages) :

-
console.log('ä'.localeCompare('z', 'de')); // a negative value: in German, ä sorts with a
+
console.log('ä'.localeCompare('z', 'de')); // a negative value: in German, ä sorts with a
 console.log('ä'.localeCompare('z', 'sv')); // a positive value: in Swedish, ä sorts after z
 
@@ -129,7 +129,7 @@ console.log('ä'.localeCompare('z', 'sv')); // a positive value: in Swedish, ä

localeCompare() 所提供的结果可以通过 options 参数来制定:

-
// in German, ä has a as the base letter
+
// in German, ä has a as the base letter
 console.log('ä'.localeCompare('a', 'de', { sensitivity: 'base' })); // 0
 
 // in Swedish, ä and a are separate base letters
-- 
cgit v1.2.3-54-g00ecf