JavaScripture
Contribute via GitHub Feedback

WeakMap : Object

WeakMaps allow associating keys and values similar to Map except WeakMap does not allow iterating over its keys or values. If WeakMap would be the only object holding on to the key/value pair, the pair will be released from memory. The keys cannot be primitive values (Boolean, Number, String, or undefined).

Constructors

new WeakMap() : WeakMap

Creates an empty WeakMap.

Example:

Run

Results:

 

new WeakMap(iterable : Object) : WeakMap

Creates a WeakMap by iterating over iterable and using the first element of the iterator value as the key and second element as the value.

Example:

Run

Results:

 

Instance Methods

delete(key : Object) : Boolean

Removes key and its corresponding value from this. Returns true if key was in this before deleting it.

Example:

Run

Results:

 

get(key : Object) : Object

Returns the value stored for key. If no value is stored, returns undefined. See also has() and set().

Example:

Run

Results:

 

has(key : Object) : Boolean

Returns true if the map has a value stored for key.

Example:

Run

Results:

 

set(key : Object, value : Object) : WeakMap

Stores value in this at the specified key. key cannot be a primitive value (Boolean, Number, String, or undefined). If a value is already stored for that key, it is replaced with value. Returns this. See also get() and has().

Example:

Run

Results: