class Movie {
constructor(movieName, category ) {
this._movieName = movieName;
this._category = category;
}
showMovieName() {
return `${movieName}`;
}
}
const movie1 = new Movie("Avengers", "superheroes");
console.log(movie1.showMovieName());
I have a Movie class and two fields with underscores. I need to create a method that returns the title of the movie. How can i do this? Now in the console the error movieName is not defined
>Solution :
None of your fields are private. Just prefix movieName with underscore.
showMovieName() {
return `${this._movieName}`;
}