Skip to content

Instantly share code, notes, and snippets.

@rochapablo rochapablo/.js
Created Aug 8, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.