JavaScript 对象原型 prototype


JavaScript 对象原型 prototype

<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>