A Practical Guide to JavaScript Proxy Objects

แชร์
ฝัง
  • เผยแพร่เมื่อ 24 ม.ค. 2022
  • Have you ever wondered what proxies are in JavaScript and what you can use them for? In this video, we take a look at Proxy Objects in JavaScript. We start off by creating our own implementation of the proxy, then dive into a practical application for proxies.
    🌎 Follow me here:
    Discord: / discord
    Twitter: / tomdoes_tech
    Facebook: / tomdoestech​
    Instagram: / tomdoestech​
    TikTok: / tomdoes_tech
    ☕ Buy me a coffee: www.buymeacoffee.com/tomn

ความคิดเห็น • 15

  • @Dave-dl8ey
    @Dave-dl8ey ปีที่แล้ว +2

    Tom you always have great content. Came across JS Proxy today and needed to understand it. Checked a few videos but this was the best. Tom always saves the day!

  • @prozacgod
    @prozacgod ปีที่แล้ว +3

    naming the proxy getCharacter is kinda rough, it really undermines the understanding. Calling it "characterProxy" would make vastly more sense, esp. as you expand the functionality of the proxy.
    Secondly, it may be a matter of form, but I would always use target instead of the original object when using the proxy. I think proxies are recursive, so you can proxy a proxy etc... one of your implementations refered to the original object directly, bypassing future flexibility.
    all-in-all a decent run through, with just those minor nit picks.

    • @TomDoesTech
      @TomDoesTech  ปีที่แล้ว +1

      Thanks for the feedback!

  • @Corzhy0
    @Corzhy0 2 ปีที่แล้ว +3

    This guy is a legend

  • @kashnigahbaruda
    @kashnigahbaruda 2 ปีที่แล้ว +4

    Nice!

  • @matecode359
    @matecode359 ปีที่แล้ว

    Thank u for this guide, tho i have a question. Why write 'complicated' proxy obj instead of a function which will check if an item with ID passed to our fetch function already exists in our cache? and just return if it does?

    • @TomDoesTech
      @TomDoesTech  ปีที่แล้ว +3

      Because the video was about proxy objects

    • @denverjamesduran2750
      @denverjamesduran2750 12 วันที่ผ่านมา

      ​​@@TomDoesTech Hahahahahhahahahahhaha. Anyway I think he says it because you said its a real world application or implied something about it

  • @hermana1016
    @hermana1016 ปีที่แล้ว +2

    Good video, nice to here an Australian voice instead of always American voices

  • @SachinYadav-eh7vg
    @SachinYadav-eh7vg ปีที่แล้ว

    This is a good explanation thanks for that, but why would be one using this approach of getter and setter isn't this approach more relevant towards object oriented whereas JS is functional ?

  • @8koi245
    @8koi245 ปีที่แล้ว

    13:17 don't need the Boolean just to wrap it in ( )

  • @alexanderdiakonov1340
    @alexanderdiakonov1340 ปีที่แล้ว

    How you set the value , if handler dosent have the set mothod... ??? 😵‍💫

    • @dodv6
      @dodv6 ปีที่แล้ว

      well character is set into characterCache while you fetch data from the server itself you can see the code

  • @And1997Ruz
    @And1997Ruz 10 หลายเดือนก่อน

    This is actually bad
    Don't recommend watching it, you'll ruin your understanding of the purpose of proxies
    Great channel overall, but this video is bad
    I'm sorry

  • @supremoluminary
    @supremoluminary ปีที่แล้ว

    All you need to get the `in` operator working is the grouping operator.
    if( !(1 in getCharacter)) {
    }
    It is not the case that:-
    if( !1 in getCharacter)
    - is falsey all the time. `!1` is converted ToBoolean to false. Thus, the expression is literally evaluated as:-
    if(false in getCharacter)
    - and, given that id's are numeric here, `false in getCharacter` will literally be false all the time.