Add user method to user defined class : Method « Object Oriented « JavaScript DHTML






Add user method to user defined class

  

<html>
<head>
<title>First Object</title>
<script type="text/javascript">
function Song (title) {
   this.title = title;
}
function printTitle() {
   alert(this.title);
}
var someSong = new Song("Title");
Song.prototype.print = printTitle;

var anotherSong = new Song("Another Title");
anotherSong.print();

</script>

</head>
<body>
</body>
</html>

   
    
  








Related examples in the same category

1.Add methods to a class