JS "this" and Function References - What is it all about?

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

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

  • @ernestodiaz4378
    @ernestodiaz4378 5 лет назад +13

    Uff, few people I've known, who can explain things so clearly and easily. Thanks for the video, it's awesome!

    • @academind
      @academind  5 лет назад

      Awesome to read that Ernesto, thanks a lot!

  • @CarlosUeda
    @CarlosUeda 3 года назад +1

    Normally I don't make comments in videos. But I totally recommend Max's courses. It's the best way of improving your development skills.

  • @yuriishportko5935
    @yuriishportko5935 6 лет назад +30

    Max, THANK You very much, only now I understood what for bind() is

    • @academind
      @academind  6 лет назад +3

      Happy to read that the video made things clearer for you Yurii, thank you very much for your comment!

    • @sebbelur124
      @sebbelur124 4 года назад

      At what point in the video does he cover the empty parthesis?

    • @sebbelur124
      @sebbelur124 4 года назад

      *parenthesis

  • @Deliverant
    @Deliverant 6 лет назад +9

    the 'this' in javascript it's been the hardest thing to grasp correctly for me, thankfully we now have arrow functions. But it's also super important to know how the 'this' behave because there is a tons of legacy code out there

  • @JMEPatterson
    @JMEPatterson 6 лет назад +6

    "Mind yoga" - I love it and it means you really are a Guru. Thanks for these videos. I got here backwards - I'm taking some of your Udemy courses and was so impressed that I came to RUclips to see more.

    • @academind
      @academind  6 лет назад +3

      Thanks so much for both your fantastic feedback and your support here and on Udemy James! This honestly means a lot to me!

  • @vaheghevondyan9437
    @vaheghevondyan9437 6 лет назад +1

    Every time when I watch your videos I make sure, that your explanation style is the best for me and I am sure not only for me.
    Thank you and much success in your work.

    • @academind
      @academind  6 лет назад

      It honestly makes me happy to read such awesome comments Vahe! I try my best to explain as understandable as possible and it's just fantastic to see that this explanation style works for you and others :)

  • @dmalvi2002
    @dmalvi2002 2 года назад

    You're the one of my great teachers. Still I need your videos to watch everyday or memorizing what I've learned from you before.

  • @Hossein13M
    @Hossein13M 4 года назад +4

    I really learned a lot of things by watching this video. the things I did before without knowing its reason.
    Thanks a lot, Max

  • @bowielam7866
    @bowielam7866 2 года назад

    This is the most clearest (yes i know that's not grammatically correct) video that explains both "this" and arrow function. Thank you for making this video, I finally get this solved. Thank you so so so so so much.

  • @slightlym4d
    @slightlym4d 5 лет назад +3

    I simply LOVE the way you teach and the way you explain things. Huge thank you!!!

    • @academind
      @academind  5 лет назад +1

      Feedback like yours means so much to me, thanks a lot :)

  • @babinsapkota8269
    @babinsapkota8269 2 года назад

    I just want to appreciate this content which is extremely helpful for every Javascript Developer.

  • @blacksmokegearjammer
    @blacksmokegearjammer 2 года назад

    Definitely the best explanation of 'this' I have come across. Thank you.

  • @pablokatt
    @pablokatt 6 лет назад +3

    This is this !! Very happy you have made this video Max nobody explain programming as you!!

    • @academind
      @academind  6 лет назад +1

      Thanks so much Pablo, just great to get such an awesome feedback!

  • @skullwise
    @skullwise 2 года назад

    No one could have explained this any better. you are the best!!

  • @snehakamble229
    @snehakamble229 3 года назад

    best explanation of this keyword found on internet.

  • @vugar892
    @vugar892 6 лет назад +3

    Awesome explanation! There are many tutorials trying to explain this concept but found this tutorial very helpful and easy. Thanks!

    • @academind
      @academind  6 лет назад +1

      That's just fantastic to read, thanks so much Vugar!

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

    when my company told to me to do certification from this guy on udemy I used to hate him. but now totaly depend on him to grab any type of knowledge.I have bought 4 courses of him.

  • @walljacket
    @walljacket 6 лет назад

    Finally! I am finally beginning to "wrap my brain" around "this". Thank you Max. You are awesome

    • @academind
      @academind  6 лет назад

      YOU are awesome David, thanks a lot for sharing this great feedback!

  • @mrityunjoynath7673
    @mrityunjoynath7673 2 года назад

    Came from the React - The Complete Guide. Awesome instructor.

  • @GNAFerreira
    @GNAFerreira 6 лет назад +1

    Wow!! What an amazing lesson!! I would eventually spend some 5h googling this thing around and still don't understand it well, if I hadn't watched this video. Thank you!!

    • @academind
      @academind  6 лет назад

      Happy to read that the video was helpful for you Gustavo, thanks a lot for your comment!

  • @bwanamaina
    @bwanamaina 6 лет назад +7

    Thank you Max for clarifying this

    • @academind
      @academind  6 лет назад

      Happy to read that the video was helpful for you, thank you very much for your comment!

  • @yousseftijdit
    @yousseftijdit 2 года назад

    Adding this to my favorite videos. Thank you very much Max! 'this' starts to make more sense.

  • @kenw3249
    @kenw3249 5 лет назад

    well done Max,this is the reason why in react component class you should bind method to allow it can be executed by the jsx

  • @tadtab2
    @tadtab2 6 лет назад

    I am now able to see why => functions help to resolve the problem with 'this'. I was reading it in theory and now it is with practical example. I really appreciate for the help Max.

    • @academind
      @academind  6 лет назад

      Just great to read that the video made things clearer for you, thank you very much for your comment!

  • @tanmaykrdey9293
    @tanmaykrdey9293 3 года назад +1

    Great explanation. I really love Your courses. All the step by step explanation really helped me. Thank you.

  • @abhinav4279_
    @abhinav4279_ 2 года назад

    That's what happens when you try to do multi paradigms(OOP/FUNCTIONAL) with a single language. A whole package of exceptions, yet beautiful. Nice video.

  • @syataheri9463
    @syataheri9463 2 года назад

    The best explanation of this keyword. thank's a lot, max

  • @jeremytsang9942
    @jeremytsang9942 4 года назад

    I was confused this topic before but now it totally makes sense. Great video!

  • @sukmonugrohoamd489
    @sukmonugrohoamd489 4 года назад +2

    Awesome, now i understand the basics of this thanks to you. Thank so much Academind

  • @alinamarasca2
    @alinamarasca2 3 года назад

    Finally, I got "this"! Thanks you very much!

  • @richardramos7267
    @richardramos7267 3 года назад

    I'm sooooooooooo amaze how you explain things man, you are fricking amazing.

  • @EdyGavrila
    @EdyGavrila 2 года назад

    Thanks, Max, Manu. Your video was a really nice refresher on 'this' keyword. Very clearly explained, as always in your videos.

  • @gajananpalankar3675
    @gajananpalankar3675 4 года назад +2

    Awesome Video! Really helped a lot to clear the confusion around this. Good work Max!

  • @matteobarbieri2989
    @matteobarbieri2989 6 лет назад

    great explanation Max.
    I fought a couple of times against “this” word but finally everything is much cleaner

    • @academind
      @academind  6 лет назад +1

      Awesome to read that the video helped to make things a bit clearer, "this" can indeed be confusing :)

  • @peterkirubaithilakan4752
    @peterkirubaithilakan4752 2 года назад

    Hi Max, I like the way you think and explain the content. i usually have a lot questions when follow a course but very little when I following your course as it is well explained. Keep up the good work.

  • @wobsoriano
    @wobsoriano 6 лет назад +77

    this.video = 'awesome' ;

    • @academind
      @academind  6 лет назад +1

      Thank you Robert :)

    • @ahmedanalattack
      @ahmedanalattack 6 лет назад +4

      Or maybe () => { this.video = 'awasome'} to be on a safe side :(

    • @Rilex037
      @Rilex037 6 лет назад +1

      TypeError: Cannot read property 'undefined' of undefined at yt-formatted-string.video

    • @rambo9769
      @rambo9769 4 года назад

      @@ahmedanalattack Yeah. That's what i do.

  • @Masavi86
    @Masavi86 6 лет назад

    You're my hero Max. At last i understood how the binding works! Working with React i always had this doubt of why i could use arrow functions without binding them in the constructor ☺

    • @academind
      @academind  6 лет назад +1

      Thanks so much Mauricio, so happy to read that :)

  • @ashwinkumar3531
    @ashwinkumar3531 2 года назад

    One of the best explanations out there. Thank you

  • @Gadgetoholic
    @Gadgetoholic 3 года назад

    Max - I saved this video to tutorials I'm sure I will get back to in the future. Thanks !

  • @ruchithota8725
    @ruchithota8725 2 года назад

    Very nicely explained the "THIS" keyword......:)

  • @akunanagideon2010
    @akunanagideon2010 3 года назад

    A lot of mind yoga here. Great one, Max

  • @LevviTalk
    @LevviTalk 6 лет назад

    Amazing video!
    Best explanation I've found so far on this subject.
    Everything makes sense now.

    • @academind
      @academind  6 лет назад

      Wow, what an awesome feedback, thanks so much for that!

  • @Albert-fe8jx
    @Albert-fe8jx 6 лет назад

    Great content. function versus function() -- a gold nugget. I'll have to rewatch 16:00 forward.

    • @academind
      @academind  6 лет назад

      Awesome to read that you like the video Alfred, thank you very much for your comment!

  • @Farmatique
    @Farmatique 2 года назад

    Great explanation! I remember there was another workaround before arrow functions appeared in ES6. You could say var that = this; within the constructor and then call that.addName() within button`s eventListener callback. I know, I know in 2022 probably no one use that dirt trick anymore :)

  • @barjosa31blogspot83
    @barjosa31blogspot83 6 лет назад

    A good refresher and great explanation! Thank you, Max!

    • @academind
      @academind  6 лет назад +1

      Great to read that you like it, thank you for your comment!

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

    I counted 138 x 'this' in this. :)
    Great explanation, thanks Maximilian!

  • @nitram_nosnibor
    @nitram_nosnibor 4 года назад

    Max you are bloody awesome! Thanks for explaining this SO clearly and in-depth

  • @bananapeppernov
    @bananapeppernov 6 лет назад +1

    Thank you for this and all of your other videos! Incredibly helpful!

    • @academind
      @academind  6 лет назад

      This is really great to read, thank you very much!

  • @Patrick128000
    @Patrick128000 6 лет назад

    This is freaky. I was specifically having the exact problem with arrow functions vs. normal functions and how 'this' behaves differently today. And then this video appears when I get home.

    • @academind
      @academind  6 лет назад

      Guess that was kind of a good timing then, happy to read that Patrick :)

  • @RajaseelanGaneswaran
    @RajaseelanGaneswaran 2 года назад

    Thank you - great explanation. Long live arrow functions!!

  • @cagatay7201
    @cagatay7201 2 года назад

    as Kudvenkat is the best instructor on BE, you are the best on FE I guess. Keep going!

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

    Wow..really really great explanation about this keyword

  • @aneoden9888
    @aneoden9888 7 месяцев назад

    this is GOLD! thank you so much for this great explanation, and for free! really unbelievable!

  • @Kay_Drechsler
    @Kay_Drechsler 2 года назад

    Awesome explanation like always, Max!

  • @mj2758
    @mj2758 2 года назад

    Great explanation Max you're a savior thank you

  • @amrextracoding
    @amrextracoding 4 месяца назад

    Awesome explanation, Max!
    Coming from React js Course on Udemy

  • @trevorsnyder3693
    @trevorsnyder3693 2 года назад

    Best explanation of this. Thank you!

  • @dojas64
    @dojas64 3 года назад

    Best explanation ever. Thanks, dude!

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

    This is gold. Thanks you, Max!

  • @JoeWong81
    @JoeWong81 6 лет назад

    THANK YOU VERY MUCH MAX!! I was hung up on this specific concept.

    • @academind
      @academind  6 лет назад

      Happy to read that the topic is interesting for you Joe :)

  • @huaweitrainingsafrica3742
    @huaweitrainingsafrica3742 3 месяца назад

    Best this keyword explanation. Thank you very much

  • @md.akib5124
    @md.akib5124 6 лет назад

    whoever is responsible for calling the function will be referred as this. great!!! This hint nailed this concept inside my head.

    • @academind
      @academind  6 лет назад

      Awesome to read that Mohiuddin, thank you very much!

  • @kingipra
    @kingipra 6 лет назад

    my brain is breaking but this helps out sooo much. Thank you kind sir 'this'

  • @bw7891
    @bw7891 4 года назад

    finally I know binding 'this', Thank you.Max.

    • @academind
      @academind  4 года назад

      Happy to read that Brenda, thank you!

  • @ХристоСтанков-о6к
    @ХристоСтанков-о6к 6 лет назад +1

    Perfect explanation Max! Like always... Just wanted to add something to the tutorial : my favorite way to deal with this-binding. If we include babel then we can declare the addName method in the NameGenerator class like this : " addName = () => {.....}". I like this approach because it looks so clean to me.

  • @DheerajBhaskar
    @DheerajBhaskar 6 лет назад +1

    Yes, another way would be do var self = this ;and pass self to the anonymous function. You can use self wherever you used this earlier in that scenario

  • @iseeyou5073
    @iseeyou5073 4 года назад

    those 8 people who disliked this video are the tutors jealous of your teaching skills.

  • @elmeroranchero
    @elmeroranchero 4 года назад

    for anyone wondering, addName = ( ) => { . . . } also works

  • @KetanLambat
    @KetanLambat 3 года назад

    Can we have a "this" counter on this video please.
    This video cleared the "this" concept. Thanks

  • @marinapetrovska7596
    @marinapetrovska7596 5 лет назад

    Max, your rock! If I don't become web developer with you, I don't know how else.
    I used the arrow function on line 20, with the addName function, it is another way that works just fine.
    class NameField {
    constructor(name) {
    const field = document.createElement('li');
    field.textContent = name;
    const nameListHook = document.querySelector('#names');
    nameListHook.appendChild(field);
    }
    }
    class NameGenerator {
    constructor() {
    const btn = document.querySelector('button');
    this.names = ["Max", "Anna", "Berny"];
    this.currentName = 0;
    btn.addEventListener('click', this.addName);
    }
    addName = () => {
    const name = new NameField(this.names[this.currentName]);
    this.currentName ++;
    if (this.currentName >= this.names.length) {
    this.currentName = 0;
    }
    }
    }
    const gen = new NameGenerator();

  • @عبدالقادرعبدالرحمنعبدالله

    Very helpful but challenging.
    Thank U.

  • @martinmohammed4087
    @martinmohammed4087 2 года назад

    Key sentence: The "this" keyword will not always reference directly to the class itself, where the "this" keyword is used. Rather in some cases, particular in javaScript, the 'this' keyword will reference "to the thing that calls/executes your code". A good example was the NameGenerator Class and the Constructor (inside the constructor was the 'this' keyword used. The constructor function gets called by the Class 'itself' so the 'this' keyword will reference to ....? Exactly the Class itself. Thanks ...

  • @CodingJourney
    @CodingJourney 6 лет назад +1

    Thanks Max! Quality content as usual!!

    • @academind
      @academind  6 лет назад +1

      So great to read that, thank you for your support!

  • @fuanka1724
    @fuanka1724 6 лет назад

    Very good and clear explanation, thanks!

    • @academind
      @academind  6 лет назад

      Thanks a lot for your awesome feedback!

  • @WebStack
    @WebStack 4 года назад

    Awesome Video!!! Really appreciate your efforts. Because of you, I have got confidence in coding and have started my own channel . Thanks a lot Max!! Looking forward to learn a lot from you.. :)

  • @jessievalladares
    @jessievalladares 6 лет назад

    What an excellent explanation! Thank you!

    • @academind
      @academind  6 лет назад +1

      Just awesome to read that you like the video Jessie, thanks a lot for your comment!

  • @ondrejzaruba3402
    @ondrejzaruba3402 6 лет назад +1

    this.currentName = ++this.currentName % this.names.length; :)) Nicely explained Max!

  • @buntyrajput1824
    @buntyrajput1824 2 года назад

    Thanks max finally I understand this

  • @rajatbansal100
    @rajatbansal100 5 лет назад

    Excellent explanation.

  • @natisaver
    @natisaver 3 года назад

    such a good teacher

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

    Amazing explanation!

  • @WilliamMelton617
    @WilliamMelton617 6 лет назад +1

    Amazing, informative content like always Max :)

    • @academind
      @academind  6 лет назад

      Thanks a lot William, happy to read that you like the video!

    • @WilliamMelton617
      @WilliamMelton617 6 лет назад

      Academind thanks for responding! You are my JavaScript hero lol. Are you available on any chat applications? I have a question I’d love to ask you. I been watching your Angular Material + firebase course on udemy. I am making an inventory management system and I am having a really hard time structuring my data. Could you give me some tips or maybe speak with me about it? Or should I ask my question on udemy?

  • @moviecentral4225
    @moviecentral4225 6 лет назад

    Hi Max I am ur big fan. I have purchased ur react native course . I Suggest u please update ur course . It would be beneficial for every one.

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

    Great explination! But, can you pass arguments by reference?

  • @gongchen7308
    @gongchen7308 4 года назад

    great video and I appreciate the various solutions

  • @Skaxarrat
    @Skaxarrat 6 лет назад

    Top notch video, Max

  • @MrDARKKNIGHT1000
    @MrDARKKNIGHT1000 5 лет назад +1

    HOLY FUCKING SHIT. Finally managed to understand it. Thank you Max!

  • @vk-fu7vg
    @vk-fu7vg 6 лет назад +1

    Awesome awesome stuff Max!

  • @HominisLupis
    @HominisLupis 2 года назад

    "this" is a great tutorial! Get it? Huh? Get it guys?

  • @tk7577
    @tk7577 3 года назад

    Super explanation!!

  • @prathameshsagvekar6696
    @prathameshsagvekar6696 3 года назад

    very informative. my question is, do arrow functions not contain their own `this`, like normal function do ?

  • @Gigusx
    @Gigusx 6 лет назад +1

    Thanks for the video, very informative and closed some gaps :) I did have some problems with it before I even touched ES6 and didn't really know what's going on.
    One question. How would we go about passing something into the function we're only referencing, since adding parentheses would execute it immediately when the class instance is created? One thing that comes to mind is to call that function inside an anonymous function like what you actually did in your last example, is there any other way of doing it with less code?

  • @alexnezhynsky9707
    @alexnezhynsky9707 6 лет назад

    Could also use class properties or apply a decorator that auto-resolves this.

  • @AndresReyesDev
    @AndresReyesDev 2 года назад

    You're the man... Thanks!

  • @m33gs
    @m33gs 5 лет назад +1

    with the code as it is @16:51 , lets say addName() took parameters how would the addEventListener call look like ?

    • @rickyli994
      @rickyli994 5 лет назад

      good question... i think in that case, either you write an anonymous function that takes a param, or use that arrow syntax maybe ?

  • @RobstaHendricks
    @RobstaHendricks 4 года назад

    Great description of both 'this' and arrow (or I've heard it also called a 'rocket' => in Ruby ;) ). I certainly would have been confused to see that notation.
    Is there any way to make that arrow function as a one liner?

  • @ВладимирОрлов-ш3й
    @ВладимирОрлов-ш3й 2 года назад

    great lesson! thanks!

  • @ramasamynp8175
    @ramasamynp8175 6 лет назад

    Wow complicated topic but superb explanation. I used to store this in a variable like let that = this; and then I would call that.addName

  • @PabonSarker
    @PabonSarker 6 лет назад

    Simply Awesome Max :)

  • @hbsvidu
    @hbsvidu 3 года назад

    Thanks sir !!!
    I got it
    Great explaination