Skip to content

Instantly share code, notes, and snippets.

@haidarafif0809
Last active April 4, 2018 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haidarafif0809/36fd8a3fe52d479236297e3c5fd0b3e6 to your computer and use it in GitHub Desktop.
Save haidarafif0809/36fd8a3fe52d479236297e3c5fd0b3e6 to your computer and use it in GitHub Desktop.
Use Getter and Setter in Classes Javascript
class Car {
constructor() {
this._color = null
}
get color () {
return `Warna Mobilnya adalah ${this._color}`
}
set color (color) {
this._color = `${color} keren`
}
}
const car = new Car()
car.color = 'merah'
console.log(car.color)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment