WeakMap.prototype.has()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Die Methode has()
von WeakMap
-Instanzen gibt einen boolean zurück, der angibt, ob ein Element mit dem angegebenen Schlüssel in diesem WeakMap
existiert oder nicht.
Probieren Sie es aus
const weakmap1 = new WeakMap();
const object1 = {};
const object2 = {};
weakmap1.set(object1, "foo");
console.log(weakmap1.has(object1));
// Expected output: true
console.log(weakmap1.has(object2));
// Expected output: false
Syntax
has(key)
Parameter
key
-
Der Schlüssel des Elements, dessen Vorhandensein im
WeakMap
-Objekt getestet werden soll.
Rückgabewert
Gibt true
zurück, wenn ein Element mit dem angegebenen Schlüssel im WeakMap
-Objekt existiert; ansonsten false
. Gibt immer false
zurück, wenn key
kein Objekt oder ein nicht registriertes Symbol ist.
Beispiele
Verwendung der Methode has
const wm = new WeakMap();
wm.set(window, "foo");
wm.has(window); // returns true
wm.has("baz"); // returns false
Spezifikationen
Specification |
---|
ECMAScript® 2025 Language Specification # sec-weakmap.prototype.has |
Browser-Kompatibilität
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
has |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- See implementation notes.