How to use WeakMap and WeakSet in JavaScript

preview_player
Показать описание
*My Links*

#programming #coding #typescript #javascript #frontenddeveloper #backenddeveloper #softwareengineer #softwareengineering #softwaredevelopment #weakmap #weakset #expressjs
Рекомендации по теме
Комментарии
Автор

Another place where a weakmap is useful is for diy reactivity using proxies. You can use it to store reactivity dependencies and they will be garbage collected when the dependencies are. See vue‘s reactivity system for more info.

florianbopp
Автор

that's really nice example! thank you!

ivan.romaniv
Автор

Great video didn't even know this was a thing!
What do you use to get curly if's and else's? Or is that just manual nvim config?

xelspeth
Автор

I used weekmap a lot for analytics data tracking. In case you want to build a tracking tool that is independant from the website source code, you can use weakmap to track for exemple unique impressions of elements (when they are visible on screen). This way you don't hold references to HTML elements that have been removed from the DOM and prevent them from being garbage collected

Ali-scdh
Автор

line 33: await setTimeout...?
i dont think setTimeout returns a promise

you could create:

function delay(time){return new Promise((done)=>{setTimeout(done, time || 0});}
await delay(1000 * Math.random());

schizomaru