JavaScript Getters and Setters | Mosh

Поділитися
Вставка
  • Опубліковано 29 гру 2024

КОМЕНТАРІ • 271

  • @k.safonov
    @k.safonov 5 років тому +81

    I don't understand why everyone can't explain this topic in the same way. Brilliant. Thank you very much!

    • @erhanertem196
      @erhanertem196 2 роки тому

      His voice is commercial. Everybody buys it first. When voice is welcoming, with the right attitude, pace, bang-on content, psychological impact of close shot of what he is doing (not the entire screen area) and proper-concise-basic explanation would have and certainly had brought him above all the alternate explanations. That's my friend called an educator tapping the maximum.

    • @Retrofire-47
      @Retrofire-47 2 роки тому +2

      @@erhanertem196 jeeze, someone has a crush

  • @JeremyGalloway
    @JeremyGalloway 6 років тому +424

    So much better than the CodeCademy explanation!

    • @Code325
      @Code325 5 років тому +66

      I just came here from CodeCademy too, and I totally agree!

    • @ravabat5841
      @ravabat5841 5 років тому +5

      It's true

    • @samrad6508
      @samrad6508 5 років тому +27

      it's also better than the FreeCodeCamp explanation !

    • @iamlasbrey6334
      @iamlasbrey6334 4 роки тому +19

      lol, also coming from freecodeacademy

    • @Djolesabijacica
      @Djolesabijacica 4 роки тому +1

      yeah

  • @TheJackTheLion
    @TheJackTheLion 2 роки тому +9

    You know why this is great? Because instead of just telling someone what to write and blow their mind you actually explain HOW what you are explaining came to be and WHY you would need it. Not just write this and try to get this. That is the x factor when it comes to coding tutorials. Well done as usual Mosh, I hope that made sense.

  • @sam_safari
    @sam_safari 24 дні тому

    I'm from Tanzania and Im almost 28 years on the next 2 years and i have started learning to code but this guy is amazing just straight's to the point

  • @annasezen5357
    @annasezen5357 6 років тому +108

    you could also use:
    set fullName(value) {
    [this.firstName, this.lastName] = value.split(' ')
    }

    • @1polyron1
      @1polyron1 5 років тому +9

      Good shit.

    • @sunspear1813
      @sunspear1813 5 років тому +3

      Although it's a good practice and neat trick, I think it's kind of showoff to write comments like this.

    • @noahpeltier
      @noahpeltier 5 років тому +36

      @@sunspear1813 How else was Anna supposed to share this helpful information? You can't say that commenting alternate methods that seem better is showing off, then teachers would always be showing off, everyone with superior knowledge would be "showing off". In fact, Mosh is showing off by posting these videos! HOW DARE HE!

    • @darksnow1111
      @darksnow1111 5 років тому +4

      @@noahpeltier YEAH then in this case the whole ES6 is show off, why should we use arrow functions!!!

    • @3riodokaos333
      @3riodokaos333 4 роки тому +5

      SunSpear said that because Anna is a woman. If it was a man's comment, he wouldn't say that. Thanks Anna and sorry for that. Keep commenting and "showing off". You help a lot of people that way.

  • @RyanGordy1
    @RyanGordy1 3 роки тому

    Mosh should teach every course, no fluff, straight to the point!

  • @climbers1376
    @climbers1376 6 років тому +13

    Getters and Setters:
    2:38-3:04, contextual use case
    3:05-3:14, purpose/rule
    3:14-5:37, how to prepare

  • @ahmadraja5426
    @ahmadraja5426 Рік тому

    Thank you for explaining this from first principles.
    Starting with a simple object, giving scenarios for why you'd need to implement this, and going from there.

  • @zakhariihusar6975
    @zakhariihusar6975 3 роки тому +1

    Glad you started this video with a reason why we need this👍

  • @guoxinn
    @guoxinn 6 років тому +18

    Thank you for the awesome explanation, John Smith!!

    • @dgua2917
      @dgua2917 5 років тому

      😂😂😂

  • @dianaordonez6747
    @dianaordonez6747 3 роки тому

    Amazing! I understood this better than others spanish channels. Thank you

  • @BHVampireLF
    @BHVampireLF 2 роки тому

    Ohhhh, so that's the difference, I finally understood, thank you very much. 💕 Awesome explanation.
    This is the kind of stuff I read before for the question "What's the difference/advantage of a getter over a simple method?", I don't know if it resolves the question because I didn't understood a thing:
    -"Given that without a getter, all we can do is poll the attribute for its value, anything else would require a special method which we would have to invoke on the value. Not insurmountable, but will take some thought."
    Reading that again made me forget what I saw in the video, I need to rewatch. 😂

  • @julibeeee408
    @julibeeee408 6 років тому +3

    This video answered ALL my questions on getters & setters. Thanks so much!

  • @armandvermeulen8221
    @armandvermeulen8221 Рік тому

    This made so much more sense, thank you for the video. Hope you are doing well.

  • @Calupp
    @Calupp 3 роки тому +5

    thank you, my current courses' explanation of how this works and its' use case was super clumsy.

  • @Baltie3
    @Baltie3 Рік тому

    Very simply explained! Formerly I got lost when other people described the same topic. Thank you very much!

  • @akrammd13
    @akrammd13 Рік тому

    with in 5 minutes Mosh helped me to understand the topic 😀

  • @ronpalmer7260
    @ronpalmer7260 Рік тому

    Love your Christmas ad. Its epic.

  • @alexlun4464
    @alexlun4464 4 роки тому +3

    You're wonderful at explaining topics like these, bravo!

  • @Pareshbpatel
    @Pareshbpatel 3 роки тому

    An excellent illustration of Getters/Setters in JavaScript. Thanks, Mosh
    {2021-09-22}

  • @krisilyubenov2372
    @krisilyubenov2372 Рік тому

    I can't believe I was able to understand this in 6 minutes compared to 3 hours of lectures. Saved my life for the exam, thanks lol

    • @sam_safari
      @sam_safari 24 дні тому

      for really this is unbelievable

  • @nour.m8205
    @nour.m8205 Рік тому

    Awesome explanation! I was struggling a bit with this concept. Thanks!

  • @Chris-ou4ej
    @Chris-ou4ej 5 років тому +2

    Thank you for clear explanation.

  • @Alex.Shalda
    @Alex.Shalda Рік тому

    perfectly explained, thank you!

  • @Wangaruro
    @Wangaruro 2 роки тому

    Wow! That's well explained 👏🔥

  • @anaraberda4677
    @anaraberda4677 2 роки тому

    thank you very much for this video. I couldn't understand this topic as I am learning at codeacademy. You managed to explain it in a simple logic way. So happy to come across you video

  • @natefr0st239
    @natefr0st239 5 років тому +2

    Simple and clean explanation, lovely!

  • @xesiusprime9360
    @xesiusprime9360 3 роки тому

    your explanations are top notch thanks dude

  • @modestas2890
    @modestas2890 6 років тому +3

    very clear explanation. Thank you.

  • @echelonanglo2226
    @echelonanglo2226 3 роки тому

    Only explanation i could find out there that made sense to me! amazing, thank you

  • @mohamedtawfik7344
    @mohamedtawfik7344 2 роки тому

    Great , professional way

  • @kimken8296
    @kimken8296 4 роки тому +1

    amazing explanation!! Thanks so much!

  • @ToddsDiscGolf
    @ToddsDiscGolf 3 роки тому

    This video really helped solidify the ideas after I spent hours on the codecademy “meal maker” project! Appetizers, mains, and desserts, oh my!

    • @jonjoio9184
      @jonjoio9184 3 роки тому

      Oh thank god not just me. I eventually gave up and followed the video and my code still doesn't work. I've been loving the course so far but this was so weird.

  • @YoBarbados
    @YoBarbados 2 роки тому

    Fantastic brother thank you very much!

  • @homeofstasis
    @homeofstasis 2 роки тому

    Insane explanation🌟

  • @dianalisova2669
    @dianalisova2669 4 роки тому +1

    Thank you so much for this clear explanation!

  • @iaml2909
    @iaml2909 5 років тому +1

    This help me a lot.
    Thank u very much. I will share this with my telegram group. Thanks again, very helpful.

  • @KleberJS
    @KleberJS 5 років тому

    I like so much your explanation about javascript. I always can understand properly

  • @sakshigosain238
    @sakshigosain238 Рік тому

    only half way in, but wow what an amazing explanation

  • @ripplesr5655
    @ripplesr5655 3 роки тому +1

    on spot! Thanks a lot for this Mosh!

  • @mayurapathak1654
    @mayurapathak1654 3 роки тому

    Thank you ! very clear explanation.

  • @komybro4208
    @komybro4208 3 роки тому

    This guy is good at explaining

  • @p1k1m4ru
    @p1k1m4ru 2 роки тому

    i really like this explanation - u earn my sub badman!

  • @raphaelugha5348
    @raphaelugha5348 4 роки тому +1

    Simple & clean. Loving it! Keep it up!

  • @zakariab7187
    @zakariab7187 6 місяців тому

    Finally i get it from this video

  • @geovaniraffaelli4508
    @geovaniraffaelli4508 6 років тому +2

    Thanks man, couldn't understand the example from Eloquent JS chapter 6 but this is crystal clear. You're the best.

    • @hzmi_
      @hzmi_ 6 років тому

      I couldn't understand anything from Eloquent JS lmao

    • @hzmi_
      @hzmi_ 6 років тому

      Maybe. I think the examples were a little too complex for me in Eloquent JS. Anyway, your video was helpful! Thank you Mosh.

    • @geovaniraffaelli4508
      @geovaniraffaelli4508 6 років тому +1

      Hey iMpetus. Even though it's a complex book and sometimes you have to reach for other resources in order to fully comprehend things, I still 100% recommend it because once you get through it you'll have a solid understanding of the concepts.

    • @hzmi_
      @hzmi_ 6 років тому

      Thanks for sharing your insight Nanika. I will give it another try. :)

    • @147dileep
      @147dileep 6 років тому

      @@programmingwithmosh sir, why you always use "const" rather than "var" or "let"...?

  • @kentarotanaka568
    @kentarotanaka568 6 років тому

    Thank you!!! This is 1000x better than Treehouse's video on getters and setters. Their instructor they currently have is horrible. Plus it doesn't help when their sample code are using the same variable name that's confusing the heck out me. "get owner(){....} set owner(owner){this._owner = owner; ....}. What the heck is going on! Also thanks for going over pre es2015 code. I would like to know or at least recognized the previous format when I come across it.

  • @joeya2330
    @joeya2330 4 роки тому +12

    English subtitles: Mosh Hamedani ( Marsh comma daddy )

  • @jameshayes3810
    @jameshayes3810 3 роки тому

    Great explanation. Thank you so much. I have ticked the bell icon :)

  • @ZakiZaki-eo7qh
    @ZakiZaki-eo7qh 2 роки тому

    very informative and straight to the point thank you so much !

  • @coced
    @coced 6 років тому +1

    You have no idea how long i tried to understand this

  • @alisasenicic919
    @alisasenicic919 3 роки тому

    Great explanation!!! All videos are really great explained! Great teacher skills!

  • @SorakaOTP462
    @SorakaOTP462 2 роки тому

    this is one of the hardest types of syntaxes to grasp. The second you look away and try to write on your own, you feel lost.

  • @Mikef05316338
    @Mikef05316338 3 роки тому

    Thank you so so much. Just...thanks man!!!

  • @mohanrajmanneeswaran1076
    @mohanrajmanneeswaran1076 4 роки тому

    better then codeCademy explanation!

  • @rabeehco
    @rabeehco 2 роки тому

    Thanks Hamadani!

  • @chapman8369
    @chapman8369 6 років тому

    thanks for explaining, finally understand setters

  • @sonamuhialdeen7866
    @sonamuhialdeen7866 3 роки тому

    Awesome tutorial

  • @misterhtmlcss
    @misterhtmlcss 6 років тому +3

    Very clear on how they work, but I think this one really needed more context e.g. this is a FEW use cases that are common. I felt like I walked away going cool, that's easy to implement, but without any clue on common use cases and I think this one would need that further context. Still a great video, just left me understanding something now that I won't likely use due to my not getting a grasp on when to use it.

  • @shauncomino5849
    @shauncomino5849 6 років тому

    so helpful. very glad i came here

  • @studyaddicts2772
    @studyaddicts2772 4 роки тому +1

    Sushant sir😍😍

  • @tonalmeida6023
    @tonalmeida6023 3 роки тому

    Best teatcher.

  • @Karlponken
    @Karlponken 3 роки тому

    Quick and good explanation, thanks alot!

  • @farahmaulida1278
    @farahmaulida1278 5 років тому

    MUUUCH MUCH better than codeacademy !thanks man

  • @ladyking83
    @ladyking83 2 роки тому

    if you execute the line 10 (person.fullName = 'John Smith') in 2:44, the object method would be replaced with a property having "John Smith" as its value.

  • @luis96xd
    @luis96xd 4 роки тому

    Whoa, nice video, it was a great explanation 😄

  • @shakeelahmedsiddiqi
    @shakeelahmedsiddiqi 6 років тому +1

    Awesome video for beginners.

  • @mariodmp
    @mariodmp 6 років тому +9

    Finally a simple and concise explanation about getters and setters, well done Mosh, but any particular reason why you didn't use "this" instead of firstName and lastName on the getter just like you did on the setter?
    I tested it and it worked fine for me, it seems that you just didn't do it cause you copied the whole expression from a console.log outside of the object itself.

  • @yuvrajshukla4616
    @yuvrajshukla4616 3 роки тому

    nice explanation

  • @Mooblr
    @Mooblr 5 років тому

    Great video, thanks mosh

  • @seekingcode
    @seekingcode 5 років тому

    Great explanation! Thank you.

  • @matrixInvader
    @matrixInvader 2 роки тому

    @2:34 you say that a disadvantage with regular methods is that they are 'read-only' and therefore "We cannot set the person's fullName from the outside."
    How do you mean?
    person.fullName = "Bob Brown"

  • @russ_the_ceo6456
    @russ_the_ceo6456 Рік тому

    Thank you!

  • @mateuszjamroz9994
    @mateuszjamroz9994 4 роки тому +3

    Hi nice tutorial, but why can't we do the smae task whitout naming those functions get and set?

  • @fredpourlesintimes
    @fredpourlesintimes 4 роки тому

    Good explanation.

  • @Ma1ne2
    @Ma1ne2 3 роки тому +2

    How is this related to classes? I know this concept from back in the days when I learned Java to access class attributes. Here I can also do it with objects and that's great, but how is this related to the new ES6 classes in JS?

  • @lycan2494
    @lycan2494 5 років тому +20

    i sort of get this explanation... but not 100% about this my mind is a bit torn

    • @rezvlt9285
      @rezvlt9285 3 роки тому

      Don't worry not everyone understands it 100% from watching videos. Once you start using these when building stuff you will truly understand.

  • @fefuzii
    @fefuzii 3 роки тому

    Thanks a lot man

  • @boozflooz6255
    @boozflooz6255 Рік тому

    That's awesome, understood it fast because of your explanation. What theme are you using, btw?

  • @mrmyko
    @mrmyko 6 років тому +5

    I like this explanation, because on teamtreehouse.com, I was confused and they didn't explain why and when we use getters and setters clearly

    • @pimwiphac.829
      @pimwiphac.829 5 років тому

      I was also searching for the explanation right after I watched the videos in Treehouse. Same team! XD

  • @shubhamsarohi9231
    @shubhamsarohi9231 4 роки тому +1

    Hi Mosh,
    The getter setter implementation in this video is different from the one in your course of OOP.
    Can you please explain which one is better?

  • @sidequestuk
    @sidequestuk 2 роки тому

    Really god thank you!

  • @Gwgitu77
    @Gwgitu77 10 місяців тому

    Thanks a lot

  • @HassanMalikTW
    @HassanMalikTW 6 років тому +1

    amazing explanation

  • @adriatic123
    @adriatic123 4 роки тому +1

    This is a great lecture on getters/setters. Yet I don't understand why can't we use same methods without get/set prefixes. What's the difference, i.e. what is the benefit of using get/set prefixes

    • @PsychoDude
      @PsychoDude Рік тому

      he explained it tho on the vid but you vant get a function ad a property without a get u would need to use obj.funcName() and other things in the video

  • @OneBrokeBloke
    @OneBrokeBloke 2 роки тому +1

    As someone who isnt far in JS, i dont see why i would bother adding this complexity for that result.
    I dont mind writing object.method() like this, and i dont know often i would need to change something outside the object

  • @andreekzz
    @andreekzz 6 років тому

    Excellent. Ty alot

  • @sirbalafort2620
    @sirbalafort2620 3 роки тому

    great vid

  • @DUO_QUEST
    @DUO_QUEST 4 роки тому

    Now it's clear to me :)

  • @oghenefokethompson7407
    @oghenefokethompson7407 4 роки тому

    hi mosh you have an amazing style in explanation but please i need your data structure course in JavaScript

  • @rubayaat54
    @rubayaat54 6 років тому

    Thanks Mosh

  • @evans8245
    @evans8245 6 років тому

    bless u, please, never stop what u are doing, im picking this lifeskill and frankly, thanks alot

  • @strangeDog
    @strangeDog 2 роки тому

    感謝分享🙏

  • @Misch1efManaged
    @Misch1efManaged 3 роки тому

    I don't understand why you set the "this.firstName" and "this.lastName" are set to "part[0]" and "part[1]" respectively (timestamp: 4:45). are you denoting the different parts of the string in "person.fullName" as indexes?

    • @137dylan
      @137dylan 3 роки тому

      In the "set fullName(value)" function, "value" is the string that's being passed in (in this case, it's "John Smith"). The "value.split (' ')" line is splitting the string at the space mark (hence the (' ')), so now we have an array of two elements, the first being "John", and the second being "Smith". "John" is at index 0 of the array, and "Smith" is at index 1. "this.firstName = parts[0"] then assigns the first index of the array ("John") to firstName, and "this.lastName = parts[1]" assigns the second index of the array ("Smith") to lastName.

  • @goshomalkiqify
    @goshomalkiqify 4 роки тому

    instant Like and Sub. Thank you!

  • @ibrahimsinan7994
    @ibrahimsinan7994 4 роки тому +1

    Thank you Mosh! AMAZING explanation. Do you have courses on Udemy?

  • @anurajms
    @anurajms 2 роки тому

    thank you

  • @sdfadddfasd5990
    @sdfadddfasd5990 5 років тому +4

    Your explanations r so good , please do a JS codecademy walkthrough explanation, their explanations are rubbish

    • @evgheniiturco9268
      @evgheniiturco9268 5 років тому

      this would be soooo cool

    • @conorm2524
      @conorm2524 4 роки тому

      Yeah, what is the deal with that? I lose my mind with Codecademy almost every day.

  • @aswaths4184
    @aswaths4184 3 роки тому

    ur amazing

  • @paudelamarianaoancea3761
    @paudelamarianaoancea3761 4 роки тому

    is this. refereing to the person object ? or to the fullName method ?