prototype
优质
小牛编辑
127浏览
2023-12-01
prototype属性允许您向任何对象添加属性和方法(Number,Boolean,String,Date等)。 注意:Prototype是一个全局属性,几乎可用于所有对象。
语法 (Syntax)
object.prototype.name = value
Example:Date.prototype
var myBook = new book("Perl", "Mohtashim");
book.prototype.price = null;
myBook.price = 100;
console.log("Book title is : " + myBook.title + "<br>");
console.log("Book author is : " + myBook.author + "<br>");
console.log("Book price is : " + myBook.price + "<br>");
成功执行上述代码后,将显示以下输出。
Book title is : Perl
Book author is : Mohtashim
Book price is : 100