aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/string/concat/index.html
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/javascript/reference/global_objects/string/concat/index.html
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/string/concat/index.html')
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/string/concat/index.html83
1 files changed, 83 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/concat/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/concat/index.html
new file mode 100644
index 0000000000..ee2d8dd06d
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/global_objects/string/concat/index.html
@@ -0,0 +1,83 @@
+---
+title: String.prototype.concat()
+slug: Web/JavaScript/Reference/Global_Objects/String/concat
+tags:
+ - JavaScript
+ - Method
+ - Prototype
+ - String
+translation_of: Web/JavaScript/Reference/Global_Objects/String/concat
+---
+<div>{{JSRef}}</div>
+
+<p><strong><code>concat()</code></strong> 方法将一个或多个字符串与原字符串连接合并,形成一个新的字符串并返回。</p>
+
+<h2 id="Syntax" name="Syntax">语法</h2>
+
+<pre class="notranslate"><code><var>str</var>.concat(<var>str2</var>, [, ...<var>strN</var>])</code></pre>
+
+<h3 id="Parameters" name="Parameters">参数</h3>
+
+<dl>
+ <dt><code><var>str2</var> [, ...<var>strN</var>]</code></dt>
+ <dd>需要连接到 <code><var>str</var></code> 的字符串。</dd>
+</dl>
+
+<h3 id="返回值">返回值</h3>
+
+<p>一个新的字符串,包含参数所提供的连接字符串。</p>
+
+<h2 id="Description" name="Description">描述</h2>
+
+<p><code>concat</code> 方法将一个或多个字符串与原字符串连接合并,形成一个新的字符串并返回。 <code>concat</code> 方法并不影响原字符串。</p>
+
+<p>如果参数不是字符串类型,它们在连接之前将会被转换成字符串。</p>
+
+<h2 id="性能" style="margin-bottom: 20px; line-height: 30px;">性能</h2>
+
+<p>强烈建议使用<a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Assignment_Operators">赋值操作符</a>(<code>+</code>, <code>+=</code>)代替 <code>concat</code> 方法。</p>
+
+<h2 id="Examples" name="Examples">示例</h2>
+
+<h3 id="Examples" name="Examples">使用 <code>concat</code></h3>
+
+<p>下面的例子演示如何将多个字符串与原字符串合并为一个新字符串</p>
+
+<pre class="brush: js notranslate">let 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!"
+
+"".concat({}) // [object Object]
+"".concat([]) // ""
+"".concat(null) // "null"
+"".concat(true) // "true"
+"".concat(4, 5) // "45"</pre>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-string.prototype.concat', 'String.prototype.concat')}}</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<p>{{Compat("javascript.builtins.String.concat")}}</p>
+
+<h2 id="相关链接">相关链接</h2>
+
+<ul>
+ <li>{{jsxref("Array.prototype.concat()")}}</li>
+ <li>{{jsxref("Operators/Assignment_Operators", "Assignment operators", "", 1)}}</li>
+</ul>