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
WeakMapfunction by default.
Methods
WeakMap.prototype.delete(key)- Removes any value associated to the
key.WeakMap.prototype.has(key)will returnfalseafterwards. WeakMap.prototype.get(key)- Returns the value associated to the
key, orundefinedif there is none. WeakMap.prototype.has(key)- Returns a Boolean asserting whether a value has been associated to the
keyin theWeakMapobject or not. WeakMap.prototype.set(key, value)- Sets the value for the
keyin theWeakMapobject. Returns theWeakMapobject. WeakMap.prototype.clear()Removes all key/value pairs from theWeakMapobject. Note that it is possible to implement aWeakMap-like object that has a.clear()method by encapsulating aWeakMapobject that hasn't it (see example on pageWeakMap)
Specifications
| Specification | Status | Comment |
|---|---|---|
| ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'WeakMap.prototype' in that specification. |
Standard | Initial definition. |
| ECMAScript 2017 Draft (ECMA-262) The definition of 'WeakMap.prototype' in that specification. |
Draft |
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | 36 | 6.0 (6.0) | 11 | 23 | 7.1 |
| Ordinary object | ? | 40 (40) | ? | ? | ? |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | No support | No support | 6.0 (6.0) | No support | No support | 8 |
| Ordinary object | ? | ? | 40.0 (40) | ? | ? | ? |