Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active May 30, 2022 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcsee/ab050467c32205a1b8623352f6bb8dd8 to your computer and use it in GitHub Desktop.
Save mcsee/ab050467c32205a1b8623352f6bb8dd8 to your computer and use it in GitHub Desktop.
class Moviegoer {
constructor(age) {
this.age = age;
}
watchXRatedMovie() {
if (this.age < 18)
throw new Error("You are not allowed to watch this movie");
else
this.watchMovie();
}
watchMovie() {
// ..
}
}
let jane = new Moviegoer(12);
jane.watchXRatedMovie();
// Throws exception since Jane is too young to watch the movie
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment