From 310fd066e91f454b990372ffa30e803cc8120975 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 12:56:40 +0100 Subject: unslug zh-cn: move --- .../global_objects/string/prototype/index.html | 187 --------------------- .../global_objects/string/trimend/index.html | 84 +++++++++ .../global_objects/string/trimleft/index.html | 122 -------------- .../global_objects/string/trimright/index.html | 84 --------- .../global_objects/string/trimstart/index.html | 122 ++++++++++++++ 5 files changed, 206 insertions(+), 393 deletions(-) delete mode 100644 files/zh-cn/web/javascript/reference/global_objects/string/prototype/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/string/trimend/index.html delete mode 100644 files/zh-cn/web/javascript/reference/global_objects/string/trimleft/index.html delete mode 100644 files/zh-cn/web/javascript/reference/global_objects/string/trimright/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/string/trimstart/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/string') diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/prototype/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/prototype/index.html deleted file mode 100644 index 00a9695a64..0000000000 --- a/files/zh-cn/web/javascript/reference/global_objects/string/prototype/index.html +++ /dev/null @@ -1,187 +0,0 @@ ---- -title: String.prototype -slug: Web/JavaScript/Reference/Global_Objects/String/prototype -tags: - - JavaScript - - 原型 - - 参考 - - 字符串 - - 属性 -translation_of: Web/JavaScript/Reference/Global_Objects/String -translation_of_original: Web/JavaScript/Reference/Global_Objects/String/prototype ---- -
{{JSRef}}
- -

 String.prototype 属性表示 {{jsxref("String")}}原型对象。

- -
{{js_property_attributes(0,0,0)}}
- -

描述

- -

所有 {{jsxref("String")}} 的实例都继承自 String.prototype. 任何String.prototype上的改变都会影响到所有的 {{jsxref("String")}} 实例。

- -

属性

- -
-
String.prototype.constructor
-
用于创造对象的原型对象的特定的函数。
-
{{jsxref("String.prototype.length")}}
-
返回了字符串的长度。
-
N
-
用于访问第N个位置的字符,其中N是小于 {{jsxref("String.length", "length")}} 和 0之间的正整数。这些属性都是“只读”性质,不能编辑。
-
- -

方法

- -

跟HTML无关的方法

- -
-
{{jsxref("String.prototype.charAt()")}}
-
返回特定位置的字符。
-
{{jsxref("String.prototype.charCodeAt()")}}
-
返回表示给定索引的字符的Unicode的值。
-
{{jsxref("String.prototype.codePointAt()")}}
-
返回使用UTF-16编码的给定位置的值的非负整数。
-
{{jsxref("String.prototype.concat()")}}
-
连接两个字符串文本,并返回一个新的字符串。
-
{{jsxref("String.prototype.includes()")}}
-
判断一个字符串里是否包含其他字符串。
-
{{jsxref("String.prototype.endsWith()")}}
-
判断一个字符串的是否以给定字符串结尾,结果返回布尔值。
-
{{jsxref("String.prototype.indexOf()")}}
-
从字符串对象中返回首个被发现的给定值的索引值,如果没有找到则返回-1。
-
{{jsxref("String.prototype.lastIndexOf()")}}
-
从字符串对象中返回最后一个被发现的给定值的索引值,如果没有找到则返回-1。
-
{{jsxref("String.prototype.localeCompare()")}}
-
返回一个数字表示是否引用字符串在排序中位于比较字符串的前面,后面,或者二者相同。
-
{{jsxref("String.prototype.match()")}}
-
使用正则表达式与字符串相比较。
-
{{jsxref("String.prototype.normalize()")}}
-
返回调用字符串值的Unicode标准化形式。
-
{{jsxref("String.prototype.padEnd()")}}
-
在当前字符串尾部填充指定的字符串, 直到达到指定的长度。 返回一个新的字符串。
-
{{jsxref("String.prototype.padStart()")}}
-
-

在当前字符串头部填充指定的字符串, 直到达到指定的长度。 返回一个新的字符串。

-
-
{{jsxref("String.prototype.quote()")}} {{ obsolete_inline }}
-
设置嵌入引用的引号类型。
-
{{jsxref("String.prototype.repeat()")}}
-
返回指定重复次数的由元素组成的字符串对象。
-
{{jsxref("String.prototype.replace()")}}
-
被用来在正则表达式和字符串直接比较,然后用新的子串来替换被匹配的子串。
-
{{jsxref("String.prototype.search()")}}
-
对正则表达式和指定字符串进行匹配搜索,返回第一个出现的匹配项的下标。
-
{{jsxref("String.prototype.slice()")}}
-
摘取一个字符串区域,返回一个新的字符串。
-
{{jsxref("String.prototype.split()")}}
-
通过分离字符串成字串,将字符串对象分割成字符串数组。
-
{{jsxref("String.prototype.startsWith()")}}
-
判断字符串的起始位置是否匹配其他字符串中的字符。
-
{{jsxref("String.prototype.substr()")}}
-
通过指定字符数返回在指定位置开始的字符串中的字符。
-
{{jsxref("String.prototype.substring()")}}
-
返回在字符串中指定两个下标之间的字符。
-
{{jsxref("String.prototype.toLocaleLowerCase()")}}
-
根据当前区域设置,将符串中的字符转换成小写。对于大多数语言来说,{{jsxref("String.toLowerCase", "toLowerCase")}}的返回值是一致的。
-
{{jsxref("String.prototype.toLocaleUpperCase()")}}
-
根据当前区域设置,将字符串中的字符转换成大写,对于大多数语言来说,{{jsxref("String.toUpperCase", "toUpperCase")}}的返回值是一致的。
-
{{jsxref("String.prototype.toLowerCase()")}}
-
将字符串转换成小写并返回。
-
{{jsxref("String.prototype.toSource()")}} {{ Non-standard_inline() }}
-
返回一个对象文字代表着特定的对象。你可以使用这个返回值来创建新的对象。重写 {{jsxref("Object.prototype.toSource")}} 方法。
-
{{jsxref("String.prototype.toString()")}}
-
返回用字符串表示的特定对象。重写 {{jsxref("Object.prototype.toString")}} 方法。
-
{{jsxref("String.prototype.toUpperCase()")}}
-
将字符串转换成大写并返回。
-
{{jsxref("String.prototype.trim()")}}
-
从字符串的开始和结尾去除空格。参照部分 ECMAScript 5 标准。
-
{{jsxref("String.prototype.trimStart()")}}
-
{{jsxref("String.prototype.trimLeft()")}} {{ Non-standard_inline() }}
-
从字符串的左侧去除空格。
-
{{jsxref("String.prototype.trimEnd()")}}
-
{{jsxref("String.prototype.trimRight()")}} {{ Non-standard_inline() }}
-
从字符串的右侧去除空格。
-
{{jsxref("String.prototype.valueOf()")}}
-
返回特定对象的原始值。重写 {{jsxref("Object.prototype.valueOf")}} 方法。
-
{{jsxref("String.prototype.@@iterator()", "String.prototype[@@iterator]()")}}
-
返回一个新的迭代器对象,该对象遍历字符串值的索引位置,将每个索引值作为字符串值返回。
-
- -

HTML wrapper methods

- -

下面的方法被限制使用,因为只对可用的HTML标签和属性提供部分支持。

- -
-
{{jsxref("String.prototype.anchor()")}}
-
<a name="name"> (hypertext target)
-
{{jsxref("String.prototype.big()")}} {{deprecated_inline}}
-
{{HTMLElement("big")}}
-
{{jsxref("String.prototype.blink()")}} {{deprecated_inline}}
-
{{HTMLElement("blink")}}
-
{{jsxref("String.prototype.bold()")}} {{deprecated_inline}}
-
{{HTMLElement("b")}}
-
{{jsxref("String.prototype.fixed()")}} {{deprecated_inline}}
-
{{HTMLElement("tt")}}
-
{{jsxref("String.prototype.fontcolor()")}} {{deprecated_inline}}
-
<font color="color">
-
{{jsxref("String.prototype.fontsize()")}} {{deprecated_inline}}
-
<font size="size">
-
{{jsxref("String.prototype.italics()")}} {{deprecated_inline}}
-
{{HTMLElement("i")}}
-
{{jsxref("String.prototype.link()")}}
-
<a href="url"> (link to URL)
-
{{jsxref("String.prototype.small()")}} {{deprecated_inline}}
-
{{HTMLElement("small")}}
-
{{jsxref("String.prototype.strike()")}} {{deprecated_inline}}
-
{{HTMLElement("strike")}}
-
{{jsxref("String.prototype.sub()")}} {{deprecated_inline}}
-
{{HTMLElement("sub")}}
-
{{jsxref("String.prototype.sup()")}} {{deprecated_inline}}
-
{{HTMLElement("sup")}}
-
- -

Specifications

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
规范状态备注
ECMAScript 1st Edition.StandardInitial definition.
{{SpecName('ES5.1', '#sec-15.5.3.1', 'String.prototype')}}{{Spec2('ES5.1')}}
{{SpecName('ES6', '#sec-string.prototype', 'String.prototype')}}{{Spec2('ES6')}}
{{SpecName('ESDraft', '#sec-string.prototype', 'String.prototype')}}{{Spec2('ESDraft')}}
- -

浏览器兼容性

- - - -

{{Compat("javascript.builtins.String.prototype")}}

- -

更多

- - diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/trimend/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/trimend/index.html new file mode 100644 index 0000000000..9c8319cb29 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/string/trimend/index.html @@ -0,0 +1,84 @@ +--- +title: String.prototype.trimRight() +slug: Web/JavaScript/Reference/Global_Objects/String/TrimRight +tags: + - JavaScript + - Method + - Prototype + - String +translation_of: Web/JavaScript/Reference/Global_Objects/String/trimEnd +--- +
{{JSRef}}
+ +

trimEnd() 方法从一个字符串的末端移除空白字符。trimRight() 是这个方法的别名。

+ +

{{EmbedInteractiveExample("pages/js/string-trimend.html")}}

+ +

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

+ +

语法

+ +
str.trimEnd();
+str.trimRight();
+ +

返回值

+ +

一个新字符串,表示从调用字串的末(右)端除去空白。

+ +

描述

+ +

trimEnd() / trimRight()方法移除原字符串右端的连续空白符并返回,trimEnd() / trimRight()方法并不会直接修改原字符串本身。

+ +

别名

+ +

为了与 {{jsxref("String.prototype.padEnd")}} 等函数保持一致,标准方法名称为trimEnd。 但是,出于Web兼容性原因,trimRight仍然是trimEnd的别名。 在某些引擎中,这意味着:

+ +
String.prototype.trimRight.name === "trimEnd";
+
+ +

示例

+ +

使用trimEnd()

+ +

下面的例子输出了小写的字符串"   foo":

+ +
var str = "   foo  ";
+
+alert(str.length); // 8
+
+str = str.trimRight();  // 或写成str = str.trimEnd();
+console.log(str.length); // 6
+console.log(str);       // '   foo'
+
+ +

Specifications

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
String.prototype.{trimStart,trimEnd}proposalStage 4Expected to be part of ES2019
+ +

Browser compatibility

+ +

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

+ +

{{Compat("javascript.builtins.String.trimEnd")}}

+ +

相关链接

+ + diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/trimleft/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/trimleft/index.html deleted file mode 100644 index bc6133cecb..0000000000 --- a/files/zh-cn/web/javascript/reference/global_objects/string/trimleft/index.html +++ /dev/null @@ -1,122 +0,0 @@ ---- -title: String.prototype.trimStart() -slug: Web/JavaScript/Reference/Global_Objects/String/TrimLeft -tags: - - JavaScript - - Method - - Prototype - - String - - 参考 - - 字符串 - - 方法 -translation_of: Web/JavaScript/Reference/Global_Objects/String/trimStart ---- -
{{JSRef}}
- -
trimStart() 方法从字符串的开头删除空格。trimLeft() 是此方法的别名。
- -
{{EmbedInteractiveExample("pages/js/string-trimstart.html")}}
- - - -

语法

- -
str.trimStart();
-str.trimLeft();
- -

返回值

- -

一个新字符串,表示从其开头(左端)除去空格的调用字符串。

- -

描述

- -

trimStart() / trimLeft() 方法移除原字符串左端的连续空白符并返回一个新字符串,并不会直接修改原字符串本身。

- -

别名

- -

为了与 {{jsxref("String.prototype.padStart")}} 等函数保持一致,标准方法名称为trimStart。 但是,出于 Web 兼容性原因,trimLeft 仍然是 trimStart 的别名。在某些引擎中,这意味着:

- -
String.prototype.trimLeft.name === "trimStart";
- -

示例

- -

使用 trimStart()

- -

下面的例子输出了小写的字符串 "foo  "

- -
var str = "   foo  ";
-
-console.log(str.length); // 8
-
-str = str.trimStart()    // 等同于 str = str.trimLeft();
-console.log(str.length); // 5
-console.log(str);        // "foo  "
-
- -

规范

- - - - - - - - - - - - - - - - -
规范状态备注
String.prototype.{trimStart,trimEnd}proposalStage 4Expected to be part of ES2019
- -

浏览器兼容性

- - - -

{{Compat("javascript.builtins.String.trimStart")}}

- -

Polyfill

- -
// https://github.com/FabioVergani/js-Polyfill_String-trimStart
-
-(function(w){
-    var String=w.String, Proto=String.prototype;
-
-    (function(o,p){
-        if(p in o?o[p]?false:true:true){
-            var r=/^\s+/;
-            o[p]=o.trimLeft||function(){
-                return this.replace(r,'')
-            }
-        }
-    })(Proto,'trimStart');
-
-})(window);
-
-
-/*
-ES6:
-(w=>{
-    const String=w.String, Proto=String.prototype;
-
-    ((o,p)=>{
-        if(p in o?o[p]?false:true:true){
-            const r=/^\s+/;
-            o[p]=o.trimLeft||function(){
-                return this.replace(r,'')
-            }
-        }
-    })(Proto,'trimStart');
-
-})(window);
-*/
- -

参见

- - diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/trimright/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/trimright/index.html deleted file mode 100644 index 9c8319cb29..0000000000 --- a/files/zh-cn/web/javascript/reference/global_objects/string/trimright/index.html +++ /dev/null @@ -1,84 +0,0 @@ ---- -title: String.prototype.trimRight() -slug: Web/JavaScript/Reference/Global_Objects/String/TrimRight -tags: - - JavaScript - - Method - - Prototype - - String -translation_of: Web/JavaScript/Reference/Global_Objects/String/trimEnd ---- -
{{JSRef}}
- -

trimEnd() 方法从一个字符串的末端移除空白字符。trimRight() 是这个方法的别名。

- -

{{EmbedInteractiveExample("pages/js/string-trimend.html")}}

- -

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

- -

语法

- -
str.trimEnd();
-str.trimRight();
- -

返回值

- -

一个新字符串,表示从调用字串的末(右)端除去空白。

- -

描述

- -

trimEnd() / trimRight()方法移除原字符串右端的连续空白符并返回,trimEnd() / trimRight()方法并不会直接修改原字符串本身。

- -

别名

- -

为了与 {{jsxref("String.prototype.padEnd")}} 等函数保持一致,标准方法名称为trimEnd。 但是,出于Web兼容性原因,trimRight仍然是trimEnd的别名。 在某些引擎中,这意味着:

- -
String.prototype.trimRight.name === "trimEnd";
-
- -

示例

- -

使用trimEnd()

- -

下面的例子输出了小写的字符串"   foo":

- -
var str = "   foo  ";
-
-alert(str.length); // 8
-
-str = str.trimRight();  // 或写成str = str.trimEnd();
-console.log(str.length); // 6
-console.log(str);       // '   foo'
-
- -

Specifications

- - - - - - - - - - - - - - - - -
SpecificationStatusComment
String.prototype.{trimStart,trimEnd}proposalStage 4Expected to be part of ES2019
- -

Browser compatibility

- -

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

- -

{{Compat("javascript.builtins.String.trimEnd")}}

- -

相关链接

- - diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/trimstart/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/trimstart/index.html new file mode 100644 index 0000000000..bc6133cecb --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/string/trimstart/index.html @@ -0,0 +1,122 @@ +--- +title: String.prototype.trimStart() +slug: Web/JavaScript/Reference/Global_Objects/String/TrimLeft +tags: + - JavaScript + - Method + - Prototype + - String + - 参考 + - 字符串 + - 方法 +translation_of: Web/JavaScript/Reference/Global_Objects/String/trimStart +--- +
{{JSRef}}
+ +
trimStart() 方法从字符串的开头删除空格。trimLeft() 是此方法的别名。
+ +
{{EmbedInteractiveExample("pages/js/string-trimstart.html")}}
+ + + +

语法

+ +
str.trimStart();
+str.trimLeft();
+ +

返回值

+ +

一个新字符串,表示从其开头(左端)除去空格的调用字符串。

+ +

描述

+ +

trimStart() / trimLeft() 方法移除原字符串左端的连续空白符并返回一个新字符串,并不会直接修改原字符串本身。

+ +

别名

+ +

为了与 {{jsxref("String.prototype.padStart")}} 等函数保持一致,标准方法名称为trimStart。 但是,出于 Web 兼容性原因,trimLeft 仍然是 trimStart 的别名。在某些引擎中,这意味着:

+ +
String.prototype.trimLeft.name === "trimStart";
+ +

示例

+ +

使用 trimStart()

+ +

下面的例子输出了小写的字符串 "foo  "

+ +
var str = "   foo  ";
+
+console.log(str.length); // 8
+
+str = str.trimStart()    // 等同于 str = str.trimLeft();
+console.log(str.length); // 5
+console.log(str);        // "foo  "
+
+ +

规范

+ + + + + + + + + + + + + + + + +
规范状态备注
String.prototype.{trimStart,trimEnd}proposalStage 4Expected to be part of ES2019
+ +

浏览器兼容性

+ + + +

{{Compat("javascript.builtins.String.trimStart")}}

+ +

Polyfill

+ +
// https://github.com/FabioVergani/js-Polyfill_String-trimStart
+
+(function(w){
+    var String=w.String, Proto=String.prototype;
+
+    (function(o,p){
+        if(p in o?o[p]?false:true:true){
+            var r=/^\s+/;
+            o[p]=o.trimLeft||function(){
+                return this.replace(r,'')
+            }
+        }
+    })(Proto,'trimStart');
+
+})(window);
+
+
+/*
+ES6:
+(w=>{
+    const String=w.String, Proto=String.prototype;
+
+    ((o,p)=>{
+        if(p in o?o[p]?false:true:true){
+            const r=/^\s+/;
+            o[p]=o.trimLeft||function(){
+                return this.replace(r,'')
+            }
+        }
+    })(Proto,'trimStart');
+
+})(window);
+*/
+ +

参见

+ + -- cgit v1.2.3-54-g00ecf