A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/add below:

WeakSet.prototype.add() - JavaScript | MDN

WeakSet.prototype.add()

Baseline Widely available

Die add() Methode von WeakSet Instanzen fügt ein neues Objekt am Ende dieses WeakSet hinzu.

Probieren Sie es aus
const weakset = new WeakSet();
const object = {};

weakset.add(object);
console.log(weakset.has(object));
// Expected output: true

try {
  weakset.add(1);
} catch (error) {
  console.log(error);
  // Expected output (Chrome): TypeError: Invalid value used in weak set
  // Expected output (Firefox): TypeError: WeakSet value must be an object, got 1
  // Expected output (Safari): TypeError: Attempted to add a non-object key to a WeakSet
}
Syntax Parameter
value

Muss entweder ein Objekt oder ein nicht registriertes Symbol sein. Der Wert, der zur WeakSet Sammlung hinzugefügt werden soll.

Rückgabewert

Das WeakSet Objekt.

Ausnahmen
TypeError

Wird ausgelöst, wenn value weder ein Objekt noch ein nicht registriertes Symbol ist.

Beispiele Verwendung von add
const ws = new WeakSet();

ws.add(window); // add the window object to the WeakSet

ws.has(window); // true

// WeakSet only takes objects as arguments
ws.add(1);
// results in "TypeError: Invalid value used in weak set" in Chrome
// and "TypeError: 1 is not a non-null object" in Firefox
Spezifikationen Browser-Kompatibilität Siehe auch MDN-Feedback-Box War diese Übersetzung hilfreich?

Diese Seite wurde automatisch aus dem Englischen übersetzt.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4