Use at() for Arrays in JavaScript (Transpiling vs Polyfilling, ‘this’, Babel & core-js)

Поделиться
HTML-код
  • Опубликовано: 4 окт 2024

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

  • @ByteGrad
    @ByteGrad  7 месяцев назад +1

    My Professional React & Next.js course is OUT NOW now! Find it here: bytegrad.com/courses/professional-react-nextjs -- this is the #1 resource to master the latest React & Next.js, my absolute best work.

  • @lucas.codes.tutorials
    @lucas.codes.tutorials Год назад +57

    Thank you! I've learned a lot :) Just a small detail: the polyfill at method as it is written only works with -1, but it breaks with -2, -3, etc... You just need to change that first if statement to this: if(index

    • @ByteGrad
      @ByteGrad  Год назад +25

      Oops, should be + index indeed, not - 1. Thanks!

    • @jotasenator
      @jotasenator Год назад +3

      figured it out the same. that shows that we love this content and we are learning a lot, thanks and more content to come

  • @doesitreallymatterthough-n4t
    @doesitreallymatterthough-n4t Год назад +15

    Great video, I especially liked the polyfill and "this" explanations.

    • @ByteGrad
      @ByteGrad  Год назад +1

      Glad you liked it 😁

  • @HenryBabbage
    @HenryBabbage Год назад +2

    Thank you for the great video. I hadn't taken the time to properly understand polyfilling and didn't realise frameworks like NextJS provide some polyfilling for users. This was really well explained and demonstrated in 9 mins!

  • @mateusztwardy64
    @mateusztwardy64 Год назад +3

    Happy I discovered your channel. Please add more fundamentals js nowledge videos. Cheers !

  • @fotyG
    @fotyG Год назад +3

    You explain things really well, very informative and interesting video once again. Thank you very much! 🙏🏽

  • @LePhenixGD
    @LePhenixGD Год назад +1

    I didn't know you could use the .at() method on strings too, very nice !

  • @mehmetedex
    @mehmetedex Год назад +1

    your explanation is so good

  • @nomadshiba
    @nomadshiba Год назад +4

    also use ??= instead of = while defining the prototype function
    so you dont overwrite the native one if it exists already

    • @kzl1nus648
      @kzl1nus648 Год назад +1

      If your implementation is not to spec you will get inconsistent behaviour across browsers. Always redefining means possibly not to spec but atleast its consistant which is way better imo. Didn't know that ??= was a thing, pretty cool syntax

  • @kamehameha38
    @kamehameha38 Год назад +1

    Incredibly video. I've learned alot

  • @Tysian
    @Tysian Год назад +1

    Some people are not using Next.js or even not using React at all. It would be cool to hear couple of words about how Vite handles transpiling and polyfilling 🤔

  • @OpenDeepLearning
    @OpenDeepLearning Год назад +1

    I like you. I think your channel is starting to boom.

  • @eVolt99
    @eVolt99 Год назад +1

    Explained it well, good vid! I do recommend you try and adjust your audio settings, your voice is pretty quiet.

  • @HG-wu6eb
    @HG-wu6eb Год назад

    Thank you!
    It increased my knowledge.

  • @martapfahl940
    @martapfahl940 Год назад +1

    Finally we have the syntactiv sugar of Python with negative index

  • @SamyarBorder
    @SamyarBorder Год назад

    wow many good valuable information in one 9 min video

  • @creatorsremose
    @creatorsremose Год назад

    Your delivery is a cure for insomnia, my friend. I came to learn about ".at" and ended up with a 3 hour nap.

  • @filon861
    @filon861 Год назад +1

    Shouldn't it be...
    ```
    Array.prototype.at = function (index) {
    if (index < 0) {
    return this[this.length + index];
    }
    return this[index];
    };
    ```
    to make it more dynamic, cuz passing a negative index to the .at method on your polyfilling solution will always return the last item of the array?

    • @filon861
      @filon861 Год назад

      Oh nvm, someone already noticed it

  • @rammehar5531
    @rammehar5531 10 месяцев назад +1

    Great very well explain, Thank you so much brother. I have one more questions If some has their backend (apis) which is written in java and have own users registration and login feature using jwt. Then the nextjs is good for it.

  • @pratikgajjar6183
    @pratikgajjar6183 10 месяцев назад +1

    When are you launching React and next.js
    tutorial videos?

    • @ByteGrad
      @ByteGrad  10 месяцев назад +1

      Just opened :)

  • @saymon_dev
    @saymon_dev Год назад +3

    6:52 On line number 22 I think "-1" should not be hard coded.
    What if I want to get the second last item from the array? Then it will not work.

    • @EdwinVanAssen
      @EdwinVanAssen Год назад +3

      I agree with you, I would use
      this[this.length + index]

    • @ByteGrad
      @ByteGrad  Год назад +3

      Yes, that was a mistake. Should be + index indeed, not - 1. Thanks

    • @VELIXYZ
      @VELIXYZ Год назад

      @@EdwinVanAssenwhy length + index and not length - index

    • @veedjohnson
      @veedjohnson Год назад +2

      @@VELIXYZbecause length + negative index will return length - the index.
      If you use +, it’s going to change to length + the index, which isn’t what we want in this case

    • @VELIXYZ
      @VELIXYZ Год назад

      @@veedjohnson ahh heck, i got it. Forgot that we use negative index

  • @wisdom458
    @wisdom458 28 дней назад +1

    very nice!

  • @lacherolachero9409
    @lacherolachero9409 Год назад +1

    What theme ur using? I like the colors

  • @nanashi7726
    @nanashi7726 Год назад

    I’m using [ ] expression with “noUncheckedIndexedAccess” eslint option

  • @eboubaker3722
    @eboubaker3722 Год назад +6

    I feel like all these 9 minutes can be summed up in a small 60 second short.

    • @NagRock
      @NagRock Год назад

      So sum it up in 60 seconds short and share it

  • @CodeBeep
    @CodeBeep 9 месяцев назад +1

    Why is polyfilling so strangely named?

  • @ContortionistIX
    @ContortionistIX Год назад +1

    you didnt say why you use at instead of []

    • @SamyarBorder
      @SamyarBorder Год назад

      -1

    • @ContortionistIX
      @ContortionistIX Год назад +1

      you can just .at() whenever u need negative indexing, otherwise .at() runs the risk of a null pointer with no benefit

  • @hardwired66
    @hardwired66 Год назад +1

    Wauw

  • @bronzekoala9141
    @bronzekoala9141 Год назад

    Cleaner syntax, but less obvious. I prefer obvious.

    • @gustavoh5143
      @gustavoh5143 Год назад +1

      i dont know how it could be "less obvious"

    • @everyhandletaken
      @everyhandletaken Год назад

      I would agree that it is less obvious for the negative index, but it will become commonly used over time & went he given a second thought by then.
      For positive indexes, I think it’s 100% obvious, given the naming (even more so than [0] would be for a beginner too).

  • @shakhawathhossainshatu1487
    @shakhawathhossainshatu1487 Год назад

    bro i love your videos but talk slowly u are so fast