WeakMap.prototype.set()
El mètode set()
afegeix un nou element amb una key
i un value
especificats a un objecte WeakMap
.
Sintaxi
wm.set(key, value);
Paràmetres
- key
- Necesari. La clau de l'element a afegir al objecte
WeakMap.
- value
- Necesari. El valor de l'element a afegir a l'objecte
WeakMap.
Valor de retorn
L'objecte WeakMap
.
Exemples
Utilitzar el mètode set
var wm = new WeakMap();
var obj = {};
// Afegir nous elements al WeakMap
wm.set(obj, "foo").set(window, "bar"); // chainable
// Actualitzem un element en WeakMap
wm.set(obj, "baz");
Especificacions
Especificació | Estat | Comentaris |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'WeakMap.prototype.set' in that specification. |
Standard | Definició inicial |
Compatibilitat amb navegadors
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help! (en-US)
Característica | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Suport bàsic | 36 | 6.0 (6.0) | 11 | 23 | 7.1 |
Característica | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Suport bàsic | No support | 6.0 (6.0) | No support | No support | 8 |
Notes específiques per a Firefox
- Abans de Firefox 33 (Firefox 33 / Thunderbird 33 / SeaMonkey 2.30),
WeakMap.prototype.set
retornavaundefined
al no poder-se encadenar. Això s'ha arreglat (errada 1031632). El comportament es pot trobar també a Chrome/v8 (problema).