JavaScript Date Prototype Eigenschaften
- Vorherige Seite parse()
- Nächste Seite setDate()
- Nach oben JavaScript Date Referenzhandbuch
Definition und Verwendung
prototype
Der Konstruktor ermöglicht es Ihnen, neue Eigenschaften und Methoden zum Date()-Objekt hinzuzufügen.
Bei der Konstruktion der Eigenschaften werden alle Datumobjekte mit Eigenschaft und Wert zugewiesen, als Standardwert.
Bei der Konstruktion des Konstruktors können alle Datumobjekte diese Methode verwenden.
Note:Date.prototype does not refer to a single date object, but to the Date() object itself.
Note:Prototype is a global object constructor that applies to all JavaScript objects.
Instance
Create a new date method, providing a month-name property named myProp for the date object:
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 = "September"}; 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 then call the myMet method:
var d = new Date(); d.myMet(); var monthname = d.myProp;
Syntax
Date.prototype.name = value
Technical details
JavaScript version: | ECMAScript 1 |
---|
Browser support
Eigenschaften | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
prototype | Unterstützung | Unterstützung | Unterstützung | Unterstützung | Unterstützung |
Verwandte Seiten
Tutorial:JavaScript-Datenbank
Tutorial:JavaScript-Datenbankformate
Tutorial:JavaScript-Objekt-Konstruktor
- Vorherige Seite parse()
- Nächste Seite setDate()
- Nach oben JavaScript Date Referenzhandbuch