JavaScript propriété Date de prototype
Exemples
Créer une nouvelle méthodes de l'objet Date:
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"};
}
Créer un objet Date, appelez la méthode d'objet myMet:
var d = new Date();
d.myMet();
var monthname = d.myProp;
d.myMet();
var monthname = d.myProp;
sortie monthname:
var d = new Date();
d.myMet();
document.write(d.myProp);
Essayez »
Définition et utilisation
propriété prototype vous donne la possibilité d'ajouter des propriétés et des méthodes pour un objet.
Lors de la construction d'un prototype, tous les objets de date sont ajoutés par les propriétés et les méthodes par défaut.
Remarque: Vous pouvez ajouter des propriétés et des méthodes pour le prototype, mais vous ne pouvez pas affecter un objet prototype différent.Cependant, vous pouvez attribuer un nouveau prototype à un objet défini par l'utilisateur.
Remarque: Prototype est une propriété globale, qui , pour la quasi - totalité de l'objet JavaScript.
support du navigateur
Tous les principaux navigateurs supportent propriété prototype.
grammaire
Date.prototype. name = value