• Thursday , 28 May 2020

JavaScript Getters and Setters | Mosh

Code Canyon



JavaScript Getters and Setters

🔥Get the COMPLETE course (83% OFF – LIMITED TIME ONLY): http://bit.ly/2M1sp4B

Subscribe for more videos:
https://www.youtube.com/channel/UCWv7vMbMWH4-V0ZXdmDpPBA?sub_confirmation=1

Want to learn more from me? Check out my blog and courses:

http://programmingwithmosh.com
https://www.facebook.com/programmingwithmosh/


Original source

3d Ocean

Related Posts

22 Comments

  1. Muhammad Farhan
    June 6, 2019 at 18:42

    @Mosh you said that normal methods are read only and we can't use them to set values of properties, but can't we do something like this,

    let person = {
    firstName: "Muhammad",
    lastName: "Farhan",
    fullName () {
    return `${this.firstName} ${this.lastName}`
    },
    updateFullName (name) {
    [this.firstName, this.lastName] = name.split(' ')
    }
    }

    person.fullName() // Muhammad Farhan
    person.updateFullName('Mosh Hamedani')
    person.fullName() // Mosh Hamedani

    I still don't get the use of getters and setters in JavaScript.

  2. Brandon Sumner
    June 6, 2019 at 18:42

    That whole setter splitting firstName and lastName with the index is a trash workflow

  3. Peter Viglietta
    June 6, 2019 at 18:42

    This is a great video but Javascript itself is a steaming pile of dogshit dont at me

  4. Peter Viglietta
    June 6, 2019 at 18:42

    ok… just so I'm clear… the only benefit of using a getter.. is so that you don't have to call it with parentheses?

  5. ahadjon abdullaev
    June 6, 2019 at 18:42

    a little bit hard to understand
    is there any easy way???

  6. The Undertaker
    June 6, 2019 at 18:42

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

  7. Константин Сафонов
    June 6, 2019 at 18:42

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

  8. Станислав Михальков
    June 6, 2019 at 18:42

    What ide/code editor are you use?

  9. Andrew F
    June 6, 2019 at 18:42

    Great video, thanks mosh

  10. Nairi Areg
    June 6, 2019 at 18:42

    So much better then CodeCademy but without practice I'm gonna forget this after a day :((
    And nowhere to practice :'(

  11. DJ Crypto
    June 6, 2019 at 18:42

    i swear i did this code right but i keetp getting the 'invalid shorthand propety initializer' error. where can the problem be?

  12. MikeOnTheBox
    June 6, 2019 at 18:42

    Why is it person.firstName and not this.firstName? I know they both work but… PS: Going to watch the next video suggested that talks about "this" 😀

  13. Abdel-rahman gad
    June 6, 2019 at 18:42

    hi mosh you have an amazing style in explanation
    but your name aroused
    my curiosity . are you from arabic origins ?

  14. Adam Tomczyk
    June 6, 2019 at 18:42

    This is awesome. I get () {
    this._now
    } x

  15. Christopher King
    June 6, 2019 at 18:42

    Great explanation! Thank you.

  16. Anna Sezen
    June 6, 2019 at 18:42

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

  17. Andrey Bobrov
    June 6, 2019 at 18:42

    Excellent. Ty alot

  18. BluCoder
    June 6, 2019 at 18:42

    In the setter method you can use the new destructuring operator shorthand for arrays like this:
    [firstName, lastName] = value.split(' ');
    For more info: http://exploringjs.com/es6/ch_destructuring.html

  19. HA development
    June 6, 2019 at 18:42

    Thanks Mosh

  20. Julienne Bay
    June 6, 2019 at 18:42

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

  21. Cédric Coulombe
    June 6, 2019 at 18:42

    You have no idea how long i tried to understand this

  22. gc
    June 6, 2019 at 18:42

    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

Leave A Comment

You must be logged in to post a comment.