English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
prototypeEigenschaften können Attribute und Methoden zu Ihrem Date()-Objekt hinzufügen.
Hinweis:prototype ist eine globale Eigenschaft, die für fast alle Objekte (Zahlen, Arrays, Strings und Daten etc.) verfügbar ist.
Date.prototype.name = value
Erstellen Sie eine neue Methode date, um month zu-Numerische Werte in Monate umwandeln-Wert name:
Date.prototype.showMonth = function() { var arr = ['Dez#39;,'Jan#39;,'Feb#39;,'Mär#39;,'Apr#39;,'Mai#39;,'Jun#39;,'Jul#39;,'Sep#39;,'Okt#39;,'Nov#39;,'Dez#39;]; return arr[this.getMonth()]; };
Dann erstellen Sie ein Datum und rufen Sie das showMonth()-Method auf:
var d = new Date(); var month = d.showMonth();// Aufruf des neuen Methods
Alle Browser unterstützen die prototype-Eigenschaft vollständig:
Eigenschaften | |||||
prototype | Ja | Ja | Ja | Ja | Ja |