Prototype constructor() toSource() 该原型属性可以让你的属性和方法添加到任何对象(数字,布尔值,字符串和日期等)。 注 - Prototype是一个全局属性,几乎可用于所有对象。 使用以下语法创建布尔原型。 object.prototype.name = value 例 以下示例显示如何使用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", "Tom"); 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> 成功执行上述代码后,将显示以下输出。 Book title is : Perl Book author is : Tom Book price is : 100 constructor() toSource()