Skip to content

Instantly share code, notes, and snippets.

@guidani
Created October 27, 2022 19:11
Show Gist options
  • Save guidani/bf95ef54c40e2298e3176aa63be54be4 to your computer and use it in GitHub Desktop.
Save guidani/bf95ef54c40e2298e3176aa63be54be4 to your computer and use it in GitHub Desktop.
Javascript named class constructor
class Movie {
constructor(props) {
let {
name,
year,
duration,
watched
} = props;
this.name = name;
this.year = year;
this.duration = duration;
this.watched = watched;
}
}
const db = [{
duration: 160,
name: "matrix",
watched: "sim",
year: 1999
},
{
duration: 180,
name: "avatar",
watched: "sim",
year: 2012
},
{
duration: 200,
name: "avengers",
watched: "sim",
year: 2015
}
]
let watchedMovies = []
db.forEach((item) => {
let movie = new Movie({
duration: item.duration,
name: item.name,
watched: item.watched,
year: item.year
});
watchedMovies.push(movie);
})
watchedMovies.map(item => console.log(item.name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment