JavaScript DHTML/Object Oriented/Inheritance

Материал из Web эксперт
Перейти к: навигация, поиск

Class Inheritance

  
<html>
<head>
<title>Inheritance</title>
<script type="text/javascript">
function Song(title,type) {
   this.title = title;
   this.type = type;
   this.getTitle=function() {
      return "Song: " + this.title + " Type: " + this.type;
   }
}
function SubSong(title,type,artist) {
   this.artist = artist;
   this.toString("Artist is " + artist);
   Song.apply(this,arguments);
   this.toString = function () {
     return "Artist: " + this.artist + " " + this.getTitle();
   }
}
SubSong.prototype = new Song();
var song = new SubSong("name", "type", "Artist");
alert(song.toString());
</script>
</head>
<body>
</body>
</html>