Skip to content

Instantly share code, notes, and snippets.

@Maccauhuru
Last active February 27, 2019 02:15
Show Gist options
  • Save Maccauhuru/5fe4e430077aa1e9cecd621c72657ac4 to your computer and use it in GitHub Desktop.
Save Maccauhuru/5fe4e430077aa1e9cecd621c72657ac4 to your computer and use it in GitHub Desktop.
Getters & Setters Example 2
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