WeakMap.prototype

The WeakMap.prototype property represents the prototype for the WeakMap constructor.

Property attributes of WeakMap.prototype
Writable no
Enumerable no
Configurable no

Description

WeakMap instances inherit from WeakMap.prototype. You can use the constructor's prototype object to add properties or methods to all WeakMap instances.

WeakMap.prototype is itself just an ordinary object:

Object.prototype.toString.call(WeakMap.prototype); // "[object Object]"

Properties

WeakMap.prototype.constructor
Returns the function that created an instance's prototype. This is the WeakMap function by default.

Methods

WeakMap.prototype.delete(key)
Removes any value associated to the key. WeakMap.prototype.has(key) will return false afterwards.
WeakMap.prototype.get(key)
Returns the value associated to the key, or undefined if there is none.
WeakMap.prototype.has(key)
Returns a Boolean asserting whether a value has been associated to the key in the WeakMap object or not.
WeakMap.prototype.set(key, value)
Sets the value for the key in the WeakMap object. Returns the WeakMap object.
WeakMap.prototype.clear()
Removes all key/value pairs from the WeakMap object. Note that it is possible to implement a WeakMap-like object that has a .clear() method by encapsulating a WeakMap object that hasn't it (see example on page WeakMap)

Specifications

Specification Status Comment
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'WeakMap.prototype' in that specification.
Standard Initial definition.
ECMAScript Latest Draft (ECMA-262)
The definition of 'WeakMap.prototype' in that specification.
Draft  

Browser compatibility

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
prototypeChrome Full support 36Edge Full support 12Firefox Full support 6IE Full support 11Opera Full support 23Safari Full support 8WebView Android Full support 37Chrome Android Full support 36Firefox Android Full support 6Opera Android Full support 24Safari iOS Full support 8Samsung Internet Android Full support 3.0nodejs Full support 0.12
Full support 0.12
Full support 0.10
Disabled
Disabled From version 0.10: this feature is behind the --harmony runtime flag.

Legend

Full support  
Full support
User must explicitly enable this feature.
User must explicitly enable this feature.

See also