ES6 - Date Property prototype


Advertisements

The prototype property allows you to add properties and methods to any object (Number, Boolean, String, Date, etc.). Note: Prototype is a global property which is available with almost all the objects.

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>"); 

The following output is displayed on successful execution of the above code.

Book title is : Perl  
Book author is : Mohtashim  
Book price is : 100
es6_date.htm
Advertisements