JavaScript Date prototypePropiedad
Ejemplo
Cree un nuevo método para el objeto 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"};
}
Cree un objeto Date y llame al método myMet del objeto:
var d = new Date();
d.myMet();
var monthname = d.myProp;
d.myMet();
var monthname = d.myProp;
monthnameResultado:
var d = new Date();
d.myMet();
document.write(d.myProp);
Pruébalo »
Definición y uso
La propiedad prototype le permite agregar propiedades y métodos a los objetos.
Cuando se construye un prototipo, todos los objetos Date agregarán propiedades y métodos de forma predeterminada.
Nota:Puede agregar propiedades y métodos al prototipo, pero no puede asignar otros prototipos al objeto. Sin embargo, puede asignar nuevos prototipos a objetos definidos por el usuario.
Nota:Prototype es una propiedad global, lo cual es aplicable a casi todos los objetos de JavaScript.
Soporte del navegador
![]()
![]()
![]()
![]()
![]()
Todos los navegadores principales soportan la propiedad prototype.
Sintaxis
Date.prototype.name=value
Otras extensiones
Objeto Date de JavaScript