Skip to content

Instantly share code, notes, and snippets.

@qwertie
Created August 7, 2018 19:21
Show Gist options
  • Save qwertie/97a3689d95231d773ee61780e024dc1c to your computer and use it in GitHub Desktop.
Save qwertie/97a3689d95231d773ee61780e024dc1c to your computer and use it in GitHub Desktop.
class PrivateBox {
constructor(private width: number, private height: number) {}
area() { return this.width * this.height; }
}
let x = new PrivateBox(4, 5);
console.log(x.area()); // OK
console.log(x.width); // ERROR: 'width' is private and only
// accessible within class 'PrivateBox'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment