Created
February 9, 2020 01:27
-
-
Save erockdotdev/89e49b2e8a7772ea2c830b43d9684753 to your computer and use it in GitHub Desktop.
Class with getters and setters example
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 Company { | |
constructor(brand){ | |
this.brandName = brand; | |
} | |
get name() { | |
return this.brandName | |
} | |
set name(brand) { | |
this.brandName = brand; | |
} | |
} | |
const pepsi = new Company("Pepsi") | |
console.log("pepsi",pepsi) | |
console.log("what is the name:", pepsi.name) | |
pepsi.name = "Coke" | |
console.log("what is the new name:", pepsi.name) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment