JavaScript Date prototypeProperty
Example
Create a new date object method:
Date.prototype.myMet=function()
{
if (this.getMonth()==0){this.myProp="January"};
if (this.getMonth()==1){this.myProp="February"};
if (this.getMonth()==2){this.myProp="March"};
if (this.getMonth()==3){this.myProp="April"};
if (this.getMonth()==4){this.myProp="May"};
if (this.getMonth()==5){this.myProp="June"};
if (this.getMonth()==6){this.myProp="July"};
if (this.getMonth()==7){this.myProp="August"};
if (this.getMonth()==8){this.myProp="Spetember"};
if (this.getMonth()==9){this.myProp="October"};
if (this.getMonth()==10){this.myProp="November"};
if (this.getMonth()==11){this.myProp="December"};
}
{
if (this.getMonth()==0){this.myProp="January"};
if (this.getMonth()==1){this.myProp="February"};
if (this.getMonth()==2){this.myProp="March"};
if (this.getMonth()==3){this.myProp="April"};
if (this.getMonth()==4){this.myProp="May"};
if (this.getMonth()==5){this.myProp="June"};
if (this.getMonth()==6){this.myProp="July"};
if (this.getMonth()==7){this.myProp="August"};
if (this.getMonth()==8){this.myProp="Spetember"};
if (this.getMonth()==9){this.myProp="October"};
if (this.getMonth()==10){this.myProp="November"};
if (this.getMonth()==11){this.myProp="December"};
}
Create a Date object and call the object's myMet method:
var d = new Date();
d.myMet();
var monthname = d.myProp;
d.myMet();
var monthname = d.myProp;
monthnameOutput result:
var d = new Date();
d.myMet();
document.write(d.myProp);
Try it Yourself »
Definition and Usage
The prototype property allows you to add properties and methods to objects.
When constructing a prototype, all Date objects will have the properties and methods added by default.
Note:Properties and methods can be added to the prototype, but other prototypes cannot be assigned to objects. However, new prototypes can be assigned to user-defined objects.
Note:Prototype is a global property that applies to almost all JavaScript objects.
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the prototype property.
Syntax
Date.prototype.name=value
Other Extensions
JavaScript Date Object