-
-
Save rochapablo/d58d82aeee560e59c58e571615633bb3 to your computer and use it in GitHub Desktop.
ECMAScript 6 - Classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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