Last active
April 4, 2018 07:08
-
-
Save haidarafif0809/36fd8a3fe52d479236297e3c5fd0b3e6 to your computer and use it in GitHub Desktop.
Use Getter and Setter in Classes Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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