The prototype property can also be used to extend built-in JavaScript classes. In the following code, a function, isLeapYear(), is implemented that determines whether the return value of getFullYear() is a leap year. Note that the getFullYear() method is not implemented; using the prototype property, however, isLeapYear() becomes a method of the Date object and thus also has access to Date.getFullYear(). Extending the Date Class (extend.html)
|