我正在学习JS,但对Song.prototype = Object.create(Media.prototype);
和Movie.prototype = Object.create(Media.prototype);
部分的以下内容感到困惑。如果Media
函数在范围内,为什么需要它们?
function Media(title, duration) {
this.title = title;
this.duration = duration;
this.isPlaying = false;
}
Media.prototype.start = function start() {
this.isPlaying = true;
};
Media.prototype.stop = function stop() {
this.isPlaying = false;
};
function Song(title, artist, duration) {
Media.call(this, title, duration);
this.artist = artist;
}
Song.prototype = Object.create(Media.prototype);
function Movie(title, year, duration) {
Media.call(this, title, duration);
this.year = year;
}
Movie.prototype = Object.create(Media.prototype);