静态
Atomics
.xor()
method computes a bitwise XOR with a given value at a given position in the array, and returns the old value at that position. This atomic operation guarantees that no other write happens until the modified value is written back.
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.
Atomics.xor(typedArray, index, value)
typedArray
Int8Array
,
Uint8Array
,
Int16Array
,
Uint16Array
,
Int32Array
,
Uint32Array
,
BigInt64Array
,或
BigUint64Array
.
index
typedArray
to compute the bitwise XOR.
value
The number to compute the bitwise XOR with.
The old value at the given position (
typedArray[index]
).
TypeError
, if
typedArray
is not one of the allowed integer types.
RangeError
, if
index
is out of bounds in the
typedArray
.
The bitwise XOR operation yields 1, if
a
and
b
are different. The truth table for the XOR operation is:
a
|
b
|
a ^ b
|
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
For example, a bitwise XOR of
5 ^ 1
results in
0100
which is 4 in decimal.
5 0101 1 0001 ---- 4 0100
const sab = new SharedArrayBuffer(1024); const ta = new Uint8Array(sab); ta[0] = 5; Atomics.xor(ta, 0, 1); // returns 5, the old value Atomics.load(ta, 0); // 4
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'Atomics.xor' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
xor
|
Chrome
68
|
Edge
79
|
Firefox
78
|
IE No | Opera No | Safari 10.1 — 11.1 |
WebView Android
60 — 63
|
Chrome Android
60 — 63
|
Firefox Android
57
Disabled
|
Opera Android No | Safari iOS 10.3 — 11.3 |
Samsung Internet Android
No
|
nodejs 8.10.0 |
完整支持
不支持
见实现注意事项。
用户必须明确启用此特征。
Atomics
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()