Last active
February 27, 2019 02:15
-
-
Save Maccauhuru/5fe4e430077aa1e9cecd621c72657ac4 to your computer and use it in GitHub Desktop.
Getters & Setters Example 2
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
const movie = { | |
name : "The Godfather", | |
year : 1972, | |
director: 'Francis Ford Coppola', | |
imdb_Rating: 9.2, | |
set actors(name) { | |
this.cast.push(name); | |
}, | |
cast: [], | |
get movieDetails(){ | |
return ` | |
The movie : '${this.name}' was directed by ${this.director} and released in the year ${this.year}. | |
The cast includes ${this.cast}. | |
` | |
} | |
} | |
//add the main cast actors | |
movie.actors = 'Marlon Brando'; | |
movie.actors = 'James Caan'; | |
movie.actors = 'Al Pacino'; | |
movie.movieDetails; | |
//The movie : 'The Godfather' was directed by Francis Ford Coppola and released in the year 1972. | |
//The cast includes Marlon Brando, Al Pacino, James Caan. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment