JavaScript ES6 - WeakMaps

preview_player
Показать описание
Learn the different between ES6 Maps and WeakMaps with this video!
Рекомендации по теме
Комментарии
Автор

A few things to add. First, as of 19 jan 2017, you must use object as a key for a WeakMap (so it couldn't be a string). Second, setting object1 = null and trying to would also log "undefined". Otherwise the video is correct - a Map would keep a value in the memory, and WeakMap wouldn't if the object is nulled.
Cool videos, btw, a great starter into ES6.

getlittletech
Автор

That's not really how it works. In this case you are basically saying



joshjones
Автор

using let may give more of es6 kinda feeling :) but this is awesome..
and pretty quick

peripona
Автор

so basically if I'm using a graph the adjacency list needs to be a map but if I'm keeping a distance map or visited map of that graph those can be weak maps. ?

amitavamozumder
Автор

Write this code. Check the console. Get back to me.

let weakMap = new WeakMap();
let object = {'foo': 'bar'};
weakMap.set(object, 'hello from weakMap');
object = null;
console.log(weakMap);

victortodoran