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
廣告
© . All rights reserved.