JavaScript DHTML/Object Oriented/Inheritance — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 07:26, 26 мая 2010
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>