Skip to content

Instantly share code, notes, and snippets.

@alecat88
Created March 2, 2022 00:04
Show Gist options
  • Save alecat88/c1f1bd7bdc4f3b2886710001eaff9274 to your computer and use it in GitHub Desktop.
Save alecat88/c1f1bd7bdc4f3b2886710001eaff9274 to your computer and use it in GitHub Desktop.
ES12
// Let's create a class named User.
class User {
constructor() {}
// The private methods can be created by prepending '#' before
// the method name.
#generateAPIKey() {
return "d8cf946093107898cb64963ab34be6b7e22662179a8ea48ca5603f8216748767";
}
getAPIKey() {
// The private methods can be accessed by using '#' before
// the method name.
return this.#generateAPIKey();
}
}
const user = new User();
const userAPIKey = user.getAPIKey();
console.log(userAPIKey); // This will print: d8cf946093107898cb64963ab34be6b7e22662179a8ea48ca5603f8216748767
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment