Skip to content

Instantly share code, notes, and snippets.

@rochapablo
Created August 8, 2018 11:28
Show Gist options
  • Save rochapablo/d58d82aeee560e59c58e571615633bb3 to your computer and use it in GitHub Desktop.
Save rochapablo/d58d82aeee560e59c58e571615633bb3 to your computer and use it in GitHub Desktop.
ECMAScript 6 - Classes
class Movie {
constructor() {
this.title = '';
}
getTitle() {
return this.title;
}
setTitle(title) {
this.title = title;
}
}
class Theater {
constructor() {
this.movies = [];
}
getMovies() {
return this.movies;
}
setMovies(movie) {
this.movies.push(movie);
}
}
var theater = new Theater();
var movie = new Movie();
movie.setTitle('The King\'s Speech');
theater.setMovies(movie);
var movie = new Movie();
movie.setTitle('Enemy at the Gates');
theater.setMovies(movie);
var console = document.getElementById('console');
console.innerHTML = JSON.stringify(theater.getMovies());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment