aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/atomics/and/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/atomics/and/index.html')
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/atomics/and/index.html130
1 files changed, 130 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/atomics/and/index.html b/files/zh-cn/web/javascript/reference/global_objects/atomics/and/index.html
new file mode 100644
index 0000000000..87754093bc
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/global_objects/atomics/and/index.html
@@ -0,0 +1,130 @@
+---
+title: Atomics.and()
+slug: Web/JavaScript/Reference/Global_Objects/Atomics/and
+tags:
+ - Atomics
+ - JavaScript
+ - 共享内存
+ - 实验性
+ - 方法
+translation_of: Web/JavaScript/Reference/Global_Objects/Atomics/and
+---
+<div>{{JSRef}} {{SeeCompatTable}}</div>
+
+<p><code><strong>Atomics</strong></code><strong><code>.and()</code></strong> 静态方法会将给定的值与数组上的值进行按位与操作,并将结果赋值给数组,然后返回数组该位置上的旧值。此原子操作保证在写上修改的值之前不会发生其他写操作。</p>
+
+<div>{{EmbedInteractiveExample("pages/js/atomics-and.html")}}</div>
+
+
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox">Atomics.and(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> 不是一个贡献的 typed array,则抛出 {{jsxref("TypeError")}}。</li>
+ <li>如果 <code>index</code> 超出了 <code>typedArray 的边界,则抛出</code> {{jsxref("RangeError")}}。</li>
+</ul>
+
+<h2 id="描述">描述</h2>
+
+<p>假如 a 和 b 都是 1,那么按位与运算( a &amp; b)仅产生1。与操作的真值表为:</p>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th><code>a</code></th>
+ <th><code>b</code></th>
+ <th><code>a &amp; b</code></th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>0</td>
+ <td>0</td>
+ <td>0</td>
+ </tr>
+ <tr>
+ <td>0</td>
+ <td>1</td>
+ <td>0</td>
+ </tr>
+ <tr>
+ <td>1</td>
+ <td>0</td>
+ <td>0</td>
+ </tr>
+ <tr>
+ <td>1</td>
+ <td>1</td>
+ <td>1</td>
+ </tr>
+ </tbody>
+</table>
+
+<p>比如,一个按位与如 <code>5 &amp; 1</code> 的结果是 <code>0001,其十进制就是</code>1<code>。</code></p>
+
+<pre>5 0101
+1 0001
+ ----
+1 0001</pre>
+
+<h2 id="示例">示例</h2>
+
+<pre class="brush: js">var sab = new SharedArrayBuffer(1024);
+var ta = new Uint8Array(sab);
+ta[0] = 5;
+
+Atomics.and(ta, 0, 1); // returns 0, the old value
+Atomics.load(ta, 0); // 1
+</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('Shared Memory', '#Atomics.and', 'Atomics.and')}}</td>
+ <td>{{Spec2('Shared Memory')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器支持">浏览器支持</h2>
+
+
+
+<p>{{Compat("javascript.builtins.Atomics.and")}}</p>
+
+<h2 id="相关">相关</h2>
+
+<ul>
+ <li>{{jsxref("Atomics")}}</li>
+ <li>{{jsxref("Atomics.or()")}}</li>
+ <li>{{jsxref("Atomics.xor()")}}</li>
+</ul>