JavaScript Tutorial

Object prototypes
Previous Home Next

javascript Prototypes allow you to easily define methods to all instances of a particular object. Prototyping also provides the facility to add, replace, or delete methods

Syntax :

object.prototype.name = value

Example :

<html>
<head>
<script>
function book(title, author){
    this.title = title;
    this.author  = author;
}
</script>

</head>

<body>
<script>
   
   var myBook = new book("java", "prasun");
   book.prototype.price = null;
   myBook.price = 500;
   document.write("Book title is : " + myBook.title + "<br>");
   document.write("Book author is : " + myBook.author + "<br>");
   document.write("Book price is : " + myBook.price + "<br>");
</script>
</body>
</html>

Output :

Book title is : java
Book author is : prasun
Book price is : 500
Previous Home Next

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: