Say I have the following:
function Myobj = {
name: "Julia",
birthdate: "xxxx",
genres: [],
movies: [{title: "movie1", rating: 5, genre: "Horror"}, {title: "movie2", rating 3, genre: "Comedy"},{title: "movie3", rating 3, genre: "Comedy"}, {title: "movie4", rating 3, genre: "Comedy"}, {title: "movie5", rating 3, genre: "Horror"}]
}
What I want to be able to do is have some function like:
Myobj.prototype.pushMovie(somejson) {
// code to add somejson to "movies", and add the "genre" to the "genres" array
}
Such that I can go:
obj1 = new Myobj();
obj1.pushMovie({title: "movie1", rating: 5, genre: "Horror"});
Or is it better practice to override the array prototype? If so, is it possible to give a prototype a specific array as opposed to all arrays like:
Myobj.Array.prototype.pushMovie() {
// code to inherit from regular push, and do some operation to add to "genres"
}
I do not know what the syntactically correct or best approach is.
Array.