Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Commit

Permalink
Add inheritance in javascript
Browse files Browse the repository at this point in the history
Good read: Inheritance and the prototype chain

https://goo.gl/Im9q4k
  • Loading branch information
sicktastic committed Jun 1, 2016
1 parent c12a558 commit a36ab8a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
13 changes: 13 additions & 0 deletions object_oriented_javascript/playlist/media.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function Media(title, duration) {
this.title = title;
this.duration = duration;
this.isPlaying = false;
}

Media.prototype.play = function() {
this.isPlaying = true;
};

Media.prototype.stop = function() {
this.isPlaying = false;
};
12 changes: 2 additions & 10 deletions object_oriented_javascript/playlist/song.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
function Song(title, artist, duration) {
this.title = title;
Media.call(this, title, duration);
this.artist = artist;
this.duration = duration;
this.isPlaying = false;
}

Song.prototype.play = function() {
this.isPlaying = true;
};

Song.prototype.stop = function() {
this.isPlaying = false;
};
Song.prototype = Object.create(Media.prototype);

Song.prototype.toHTML = function() {
var htmlString = '<li';
Expand Down

0 comments on commit a36ab8a

Please sign in to comment.