Die statische Atomics
.or()
Methode berechnet eine bitweises ODER mit einem gegebenen Wert auf einem Wert an einer gegebenen Position im Array und gibt den alten Wert an der Position zurück. Die atomare Operation garantiert, dass kein anderer Schreibprozess während der Operation durchgeführt wird.
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.
Syntax
Atomics.and(typedArray, index, value)
Parameter
typedArray
- Ein geteiltes getrypted Integer Array. Eines von
Int8Array
,Uint8Array
,Int16Array
,Uint16Array
,Int32Array
oderUint32Array
. index
- Die Position in
typedArray
, mit der das bitweise ODER berechnet wird. value
- Die Zahl, mit der das bitweise ODER berechnet wird.
Rückgabewert
Der alte Wert an der gegebenen Position (typedArray[index]
).
Exceptions
- Erzeugt einen
TypeError
, wenntypedArray
nicht von einem erlaubten Integer Typ ist. - Erzeugt eine
TypeError
, wenntypedArray
kein geteilter Arraytyp ist. - Erzeugt ein
RangeError
, wenn derindex
nicht in den Grenzen vontypedArray
ist.
Beschreibung
Die bitweise ODER Operation ergibt nur 1, wenn eine Werte, a
oder b
, 1 ist. Die Wahrheitstabelle für die ODER Operation ist:
a |
b |
a | b |
---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 1 |
Zum Beispiel resultiert ein bitweises ODER auf 5 | 1
in 0111
, was im Dezimalsystem 5 ist.
5 0101 1 0001 ---- 5 0101
Beispiele
var sab = new SharedArrayBuffer(1024);
var ta = new Uint8Array(sab);
ta[0] = 2;
Atomics.or(ta, 0, 1); // returns 2, the old value
Atomics.load(ta, 0); // 3
Spezifikationen
Spezifikation | Status | Kommentar |
---|---|---|
ECMAScript (ECMA-262) Die Definition von 'Atomics.or' in dieser Spezifikation. |
Lebender Standard | Initiale Definition in ES2017. |
Browserkompatibilität
BCD tables only load in the browser