JavaScript Getters and Setters | Mosh




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


22 responses to “JavaScript Getters and Setters | Mosh”

  1. @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.

Leave a Reply