ES6 prototype

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

JavaScript Date()方法返回今天的日期和时间,不需要调用任何对象。语法Date()返回值返回今天的日期和时间。例var dt = Date();console.log("Current Date ",dt ...