Created
October 27, 2022 19:11
-
-
Save guidani/bf95ef54c40e2298e3176aa63be54be4 to your computer and use it in GitHub Desktop.
Javascript named class constructor
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(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