From b046c8de074c4379283a75d0ab91b90ca6e39481 Mon Sep 17 00:00:00 2001 From: JasonLamv-t Date: Sun, 9 Jul 2023 03:18:56 +0800 Subject: [PATCH 1/2] [zh-cn]: Update translation of String.concat() --- .../global_objects/string/concat/index.md | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/concat/index.md b/files/zh-cn/web/javascript/reference/global_objects/string/concat/index.md index ff7dffee3e2a4e..2e5f2344ae4d59 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/concat/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/string/concat/index.md @@ -5,52 +5,54 @@ slug: Web/JavaScript/Reference/Global_Objects/String/concat {{JSRef}} -**`concat()`** 方法将一个或多个字符串与原字符串连接合并,形成一个新的字符串并返回。 +**`concat()`** 方法将字符串参数连接到调用的字符串,并返回一个新的字符串。 + +{{EmbedInteractiveExample("pages/js/string-concat.html")}} ## 语法 -```plain -str.concat(str2, [, ...strN]) +```js-nolint +concat(str1) +concat(str1, str2) +concat(str1, str2, /* …, */ strN) ``` ### 参数 -- `str2 [, ...strN]` - - : 需要连接到 `str` 的字符串。 +- `strN` + - : 要连接到 `str` 的一个或多个字符串。 ### 返回值 -一个新的字符串,包含参数所提供的连接字符串。 +一个包含所提供的多个字符串文本组合的新字符串。 ## 描述 -`concat` 方法将一个或多个字符串与原字符串连接合并,形成一个新的字符串并返回。 `concat` 方法并不影响原字符串。 +`concat()` 函数将字符串参数连接到调用的字符串并返回一个新字符串。对原字符串或返回的字符串所做的更改不会影响另一个字符串。 如果参数不是字符串类型,它们在连接之前将会被转换成字符串。 -## 性能 - -强烈建议使用[赋值操作符](/zh-CN/docs/Web/JavaScript/Reference/Operators/Assignment_Operators)(`+`, `+=`)代替 `concat` 方法。 +`concat()` 方法与 [加号/字符串连接运算符](/zh-CN/docs/Web/JavaScript/Reference/Operators/Addition)(`+`,`+=`)非常相似,不同之处在于 `concat()` 直接将其参数强制转换为字符串进行连接,而加号运算符首先将其操作数强制转换为原始值,然后再进行连接。有关更多信息,请参阅[`+`运算符的参考页面](/zh-CN/docs/Web/JavaScript/Reference/Operators/Addition)。 ## 示例 -### 使用 `concat` +### 使用 concat() 下面的例子演示如何将多个字符串与原字符串合并为一个新字符串 ```js -let hello = 'Hello, ' -console.log(hello.concat('Kevin', '. Have a nice day.')) +const hello = "Hello, "; +console.log(hello.concat("Kevin", ". Have a nice day.")); // Hello, Kevin. Have a nice day. -let greetList = ['Hello', ' ', 'Venkat', '!'] -"".concat(...greetList) // "Hello Venkat!" +const greetList = ["Hello", " ", "Venkat", "!"]; +"".concat(...greetList); // "Hello Venkat!" -"".concat({}) // [object Object] -"".concat([]) // "" -"".concat(null) // "null" -"".concat(true) // "true" -"".concat(4, 5) // "45" +"".concat({}); // "[object Object]" +"".concat([]); // "" +"".concat(null); // "null" +"".concat(true); // "true" +"".concat(4, 5); // "45" ``` ## 规范 @@ -61,7 +63,7 @@ let greetList = ['Hello', ' ', 'Venkat', '!'] {{Compat}} -## 相关链接 +## 参见 - {{jsxref("Array.prototype.concat()")}} -- {{jsxref("Operators/Assignment_Operators", "Assignment operators", "", 1)}} +- [加法运算符](/zh-CN/docs/Web/JavaScript/Reference/Operators/Addition) From d9854e8d36d7401e9e5c2b057deea72f0e4ebdb2 Mon Sep 17 00:00:00 2001 From: Jason Lam Date: Mon, 10 Jul 2023 10:35:35 +0800 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Jason Ren <40999116+jasonren0403@users.noreply.github.com> --- .../reference/global_objects/string/concat/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/concat/index.md b/files/zh-cn/web/javascript/reference/global_objects/string/concat/index.md index 2e5f2344ae4d59..d3fd817c1aaee4 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/concat/index.md +++ b/files/zh-cn/web/javascript/reference/global_objects/string/concat/index.md @@ -32,13 +32,13 @@ concat(str1, str2, /* …, */ strN) 如果参数不是字符串类型,它们在连接之前将会被转换成字符串。 -`concat()` 方法与 [加号/字符串连接运算符](/zh-CN/docs/Web/JavaScript/Reference/Operators/Addition)(`+`,`+=`)非常相似,不同之处在于 `concat()` 直接将其参数强制转换为字符串进行连接,而加号运算符首先将其操作数强制转换为原始值,然后再进行连接。有关更多信息,请参阅[`+`运算符的参考页面](/zh-CN/docs/Web/JavaScript/Reference/Operators/Addition)。 +`concat()` 方法与[加号/字符串连接运算符](/zh-CN/docs/Web/JavaScript/Reference/Operators/Addition)(`+`,`+=`)非常相似,不同之处在于 `concat()` 直接将其参数强制转换为字符串进行连接,而加号运算符首先将其操作数强制转换为原始值,然后再进行连接。有关更多信息,请参阅 [`+` 运算符的参考页面](/zh-CN/docs/Web/JavaScript/Reference/Operators/Addition)。 ## 示例 ### 使用 concat() -下面的例子演示如何将多个字符串与原字符串合并为一个新字符串 +下面的示例将多个字符串组合为一个新字符串。 ```js const hello = "Hello, ";