The initial value of the prototype property refers to the built-in Date prototype object.
The value of the Date prototype object is NaN.
The example demonstrates how to provide extensions to all instances of this class by adding a function to the prototype object.
<HTML>
<HEAD>
</HEAD>
<BODY>
<SCRIPT>
// Define a function that extends the output capabilities of Date objects
function millennium()
{
return this.getFullYear()/1000;
}
// Register the new function
Date.prototype.millennium = millennium;
// Create a date and test the Date.millennium() method
myDate = new Date();
document.write(myDate.millennium())
document.write("<BR>")
</SCRIPT>
</BODY>
</HTML>| See also: | prototype property |
ECMA 262 edition 2 - section - 15.2.3.1
ECMA 262 edition 2 - section - 15.9.4.1
ECMA 262 edition 2 - section - 15.9.5
ECMA 262 edition 3 - section - 15.9.4.1
| Prev | Home | Next |
| Date.parse() | Up | Date.setDate() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. | ||