How to use WeakMap and WeakSet in JavaScript

Поделиться
HTML-код
  • Опубликовано: 17 апр 2024
  • My Links
    shaky.sh
    shaky.sh/tools
    / andrew8088
    mastodon.social/@andrew8088
    #programming #coding #typescript #javascript #frontenddeveloper #backenddeveloper #softwareengineer #softwareengineering #softwaredevelopment #weakmap #weakset #expressjs
  • НаукаНаука

Комментарии • 11

  • @florianbopp187
    @florianbopp187 2 месяца назад +9

    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.

    • @studiowebselect
      @studiowebselect 2 месяца назад +1

      i was about to point exactly the same reference from vue reactivity

  • @hugodsa89
    @hugodsa89 2 месяца назад +7

    Missed your videos

  • @ivan.romaniv
    @ivan.romaniv 2 месяца назад

    that's really nice example! thank you!

  • @xelspeth
    @xelspeth 2 месяца назад

    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?

  • @Ali-sc6dh
    @Ali-sc6dh 2 месяца назад

    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

  • @hugodsa89
    @hugodsa89 2 месяца назад +2

    Audio is top. Maybe don’t lean back 🤣

  • @schizomaru
    @schizomaru 2 месяца назад

    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());

    • @EccentricEngineerMN
      @EccentricEngineerMN 2 месяца назад

      In this video he is using nodejs timers/promises which is a promisified version ofr the global setTimeout