ES6 - Date 属性原型



prototype 属性使您可以向任何对象(Number、Boolean、String、Date 等)添加属性和方法。注意:Prototype 是几乎所有对象都可用的全局属性。

语法

object.prototype.name = value

示例: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
广告