The prototype attribute can add properties and methods to any object (Number, Boolean, String and Date, etc.).
Note: Prototype is a global property that can be used in almost all objects.
Grammar
object.prototype.name = value
Example:
Here is an example showing how to add properties to an object using the prototype attribute:
<html> <head> <title>User-defined objects</title> <script type="text/javascript"> function book(title, author){ this.title = title; this.author = author; } </script> </head> <body> <script type="text/javascript"> var myBook = new book("Perl", "Mohtashim"); book.prototype.price = null; myBook.price = 100; 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>
This will produce the following results:
Book title is : Perl Book author is : Mohtashim Book price is : 100