Skip to content

Instantly share code, notes, and snippets.

@erockdotdev
Created February 9, 2020 01:27
Show Gist options
  • Save erockdotdev/89e49b2e8a7772ea2c830b43d9684753 to your computer and use it in GitHub Desktop.
Save erockdotdev/89e49b2e8a7772ea2c830b43d9684753 to your computer and use it in GitHub Desktop.
Class with getters and setters example
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