aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/atomics/add/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/atomics/add/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/atomics/add/index.html')
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/atomics/add/index.html84
1 files changed, 84 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/atomics/add/index.html b/files/zh-cn/web/javascript/reference/global_objects/atomics/add/index.html
new file mode 100644
index 0000000000..256ddc4019
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/global_objects/atomics/add/index.html
@@ -0,0 +1,84 @@
+---
+title: Atomics.add()
+slug: Web/JavaScript/Reference/Global_Objects/Atomics/add
+tags:
+ - Atomics
+ - JavaScript
+ - Shared Memory
+ - 共享内存
+ - 方法
+translation_of: Web/JavaScript/Reference/Global_Objects/Atomics/add
+---
+<div>{{JSRef}}</div>
+
+<p><code><strong>Atomics</strong></code><strong><code>.add()</code></strong> 静态方法会将给定的值加到数组里的某个特定位置上,并返回该位置的旧值。此原子操作保证在写上修改的值之前不会发生其他写操作。</p>
+
+<div>{{EmbedInteractiveExample("pages/js/atomics-add.html")}}</div>
+
+
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox">Atomics.add(typedArray, index, value)
+</pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt><code>typedArray</code></dt>
+ <dd>一个共享的整型 typed array。例如 {{jsxref("Int8Array")}},{{jsxref("Uint8Array")}},{{jsxref("Int16Array")}},{{jsxref("Uint16Array")}},{{jsxref("Int32Array")}},或者 {{jsxref("Uint32Array")}}。</dd>
+ <dt><code>index</code></dt>
+ <dd><code>typedArray</code> 中的位置,该位置数值会被加总并更新。</dd>
+ <dt><code>value</code></dt>
+ <dd>增加的数字。</dd>
+</dl>
+
+<h3 id="返回值">返回值</h3>
+
+<p>给定位置的旧值(<code>typedArray[index])</code>。</p>
+
+<h3 id="错误">错误</h3>
+
+<ul>
+ <li>假如 <code>typedArray</code> 不是允许的整型之一,则抛出 {{jsxref("TypeError")}}。</li>
+ <li><code><font face="Open Sans, Arial, sans-serif">假如 </font>typedArray</code> 不是一个shared typed array类型,则抛出 {{jsxref("TypeError")}}。</li>
+ <li>如果 <code>index</code> 超出了 <code>typedArray 的边界,则抛出</code> {{jsxref("RangeError")}}。</li>
+</ul>
+
+<h2 id="示例">示例</h2>
+
+<pre class="brush: js">var sab = new SharedArrayBuffer(1024);
+var ta = new Uint8Array(sab);
+
+Atomics.add(ta, 0, 12); // returns 0, the old value
+Atomics.load(ta, 0); // 12</pre>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-atomics.add', 'Atomics.add')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td>Initial definition in ES2017.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器支持">浏览器支持</h2>
+
+
+
+<p>{{Compat("javascript.builtins.Atomics.add")}}</p>
+
+<h2 id="相关">相关</h2>
+
+<ul>
+ <li>{{jsxref("Atomics")}}</li>
+ <li>{{jsxref("Atomics.sub()")}}</li>
+</ul>