A RetroSearch Logo

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

Search Query:

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

WeakSet.prototype.add() - JavaScript | MDN

WeakSet.prototype.add()

Baseline Widely available

La méthode add() permet d'ajouter un nouvel objet à un objet WeakSet.

Exemple interactif
const weakset1 = new WeakSet();
const object1 = {};

weakset1.add(object1);
console.log(weakset1.has(object1));
// Expected output: true

try {
  weakset1.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
}
Syntaxe Paramètres
valeur

Ce paramètre est obligatoire. Il correspond à l'objet qu'on souhaite ajouter à l'ensemble WeakSet.

Valeur de retour

L'objet WeakSet.

Exemples
var ws = new WeakSet();

ws.add(window); // on ajouter l'objet window à l'objet WeakSet

ws.has(window); // tru

// WeakSet ne peut contenir que des objets
ws.add(1);
// TypeError: Invalid value used in weak set -> Chrome
// TypeError: 1 is not a non-null obect -> Firefox
Spécifications Compatibilité des navigateurs Voir aussi

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