Latest web development tutorials

JavaScript Date prototype property

Date Object Reference JavaScript Date Object

Examples

Create a new date object methods:

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

Create a Date object, call myMet object method:

var d = new Date();
d.myMet();
var monthname = d.myProp;

monthname output:

var d = new Date(); d.myMet(); document.write(d.myProp);

try it"

Definition and Usage

prototype property gives you the ability to add properties and methods to an object.

When constructing a prototype, all date objects are added by default properties and methods.

Note: You can add properties and methods to the prototype, but you can not assign a different prototype object.However, you can assign a new prototype to a user-defined object.

Note: Prototype is a global property, which for almost all of the JavaScript object.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support prototype property.


grammar

Date.prototype. name = value


Date Object Reference JavaScript Date Object