JavaScript ES6 Reflect Object

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ก.ย. 2020
  • This tutorial explains what is and how to use the ES6 Reflect Object which allows you to dynamically intercept Object property and method operations
    Typically Reflect gets used in conjunction with Proxies.
    Code from Video: gist.github.com/prof3ssorSt3v...

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

  • @abdallaabbass4271
    @abdallaabbass4271 3 ปีที่แล้ว

    Thanks very much, really you are my best teacher ❤️❤️❤️

  • @chesterxp508
    @chesterxp508 2 ปีที่แล้ว

    Another very cool tutorial!

  • @markleodionisio2669
    @markleodionisio2669 3 ปีที่แล้ว

    Thanks for sharing master.

  • @tankbottoms-yes
    @tankbottoms-yes 3 ปีที่แล้ว +1

    I’m trying to figure out how to keep track of a series of object transformations and data processing steps and it seems to me I could use Reflect to keep an array of functions to do these transforms and during some node-cron period call, iterate over the objects, call the Reflect object to check what transform function pointers need to be called and run them. Does this sound like a reasonable pattern?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 ปีที่แล้ว +1

      Reflect is not really a storage mechanism to hold lists of anything. It is a way to dynamically access an object's properties or methods. You can intercept the calls. You can delegate the calls too.
      Proxies also can work in combination with the reflection. I will have a video on that coming soon.

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

    "JavaScript From The Start" I DID IT! I completed the entire series. Thank you Steve for the many hours of valuable knowledge you have given me!! Where do I go now to complete my certificate? lol

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 ปีที่แล้ว +2

      Lol. Now go through the JavaScript in the Browser list and the APIs and AJAX playlists. Then server-side with PHP, MySQL, Node, and Express. Then the React and React Native playlists.

    • @nigelbrie5693
      @nigelbrie5693 3 ปีที่แล้ว

      @@SteveGriffith-Prof3ssorSt3v3 This is so daunting! I can't imagine making this many videos let alone learning all of this. 185 on that first list!

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 ปีที่แล้ว

      @@nigelbrie5693 no worries. I'll extend your deadline by a couple weeks. 🤪

  • @shajanjp
    @shajanjp 3 ปีที่แล้ว

    Thank you ❤️

  • @hamidallah
    @hamidallah 3 ปีที่แล้ว

    Thank you sir

  • @hanjelly5410
    @hanjelly5410 2 ปีที่แล้ว

    Nice, thanks for this summary, just an update the latest MDN doc to delete an property is changed to `Reflect.deleteProperty()`.

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

    the video didn't motivate it enough, i still don't understand how setting a "a.b" property like "a.b=3" at runtime is any less "dynamic" than doing it with Reflect

  • @pronayguha7099
    @pronayguha7099 2 หลายเดือนก่อน

    Steve, does it really add the new attribute to the object itself, or it's another copy of the same object ?

  • @janduna9187
    @janduna9187 3 ปีที่แล้ว

    Is the proxy video out ? I was unable to find it on his channel :(

  • @mod7ex_fx
    @mod7ex_fx 2 ปีที่แล้ว

    ((:: thank you my teacher

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

    first time i am seeing this.but i didn't the purpose of this reflect.becuase we can do all the above operation with Object itself.

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

      Same here.

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

      It's kind of esoteric, but there is a pretty good stackoverflow answer (all the way back from 2014!) that I think addresses some key points. For most basic operations, I suspect you may never have to use it, but it's one of those niche specialist tools in your toolbox that'll make life just a little easier when you need it.
      stackoverflow.com/questions/25421903/what-does-the-reflect-object-do-in-javascript
      Basically, Reflect is good for exceptionless handling, variable constructor arguments in ES5, setting the 'this' in some function calls, and generally avoiding older and uglier code. Oh, and proxies too.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 ปีที่แล้ว +2

      @@ProfessorSyndicateFranklai thanks for posting this.

    • @meduzfr
      @meduzfr 3 ปีที่แล้ว

      @@SteveGriffith-Prof3ssorSt3v3 Thank you for the link, Francis!
      Steve: It’s very easy to understand Reflect syntax and you explain it very well, but I think the lack of explanation about its purpose will make most people thinking that “you can do the same with Object” is the only takeaway to get here.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 ปีที่แล้ว +3

      @@meduzfr this video is really just a precursor to my video on proxies.

  • @Youssef-lv6wp
    @Youssef-lv6wp 3 ปีที่แล้ว +1

    First view Thanks u ❤

  • @LR-bc8js
    @LR-bc8js ปีที่แล้ว +1

    Great video as usual!
    However, I still don't understand what's the need of Reflect when we can do everything with objects?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  ปีที่แล้ว +1

      Reflect typically gets used with Proxy Objects. Proxy objects can be used like a standard interface wrapped around many different objects, handling and controlling access to each object. Reflect lets you easily target the specific object that you targeting. Similar to using `this` but in a more standard way that avoids differences in scope, which would alter the value of `this`.

    • @LR-bc8js
      @LR-bc8js ปีที่แล้ว +1

      @@SteveGriffith-Prof3ssorSt3v3 Make sense!
      Thank you!

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

    wbu defineMetadata and setMetadata?

  • @karimnassir5207
    @karimnassir5207 3 ปีที่แล้ว

    Why a , b equal name and id in the object ?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 ปีที่แล้ว +1

      The arguments that I passed to the function was the Array generated with Reflect.ownKeys

  • @nagendrapp2213
    @nagendrapp2213 3 ปีที่แล้ว

    could you please create some projects using js and REact

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 ปีที่แล้ว +1

      I have a playlist of videos on React - th-cam.com/video/vTFVg6I2wNI/w-d-xo.html

    • @nagendrapp2213
      @nagendrapp2213 3 ปีที่แล้ว

      @@SteveGriffith-Prof3ssorSt3v3 i have seen you have already a playlist But i want to you Create a some complex applications if possible could you please create some advanced Projects : )

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 ปีที่แล้ว

      @@nagendrapp2213 Please post any tutorial requests in the comments here - th-cam.com/video/LCezax2uN3c/w-d-xo.html

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

    I don't get the use of this when I can do all that without reflect

  • @slmshady539
    @slmshady539 3 ปีที่แล้ว

    Hey steve I have learnt a lot from you and would like to recommend you something, why don't add more videos to series JS Interview and make that playlist as one-stop for everything javascript.

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

    Sorry but this is just trash..! You don't explain why exactly you are using the Reflect object instead of using the equilavent functionalites directly available on the subject object. I mean why exactly you need to use Reflect.get(myObject, "name") instead of myObject.name or myObject["name"]?