JavaScript Date prototype özellikleri
- Önceki Sayfa parse()
- Sonraki Sayfa setDate()
- Üst Katmana Geri Dön JavaScript Date Referans Kılavuzu
Tanım ve Kullanım
prototype
Yapıcı fonksiyon, Date() nesnesine yeni özellikler ve yöntemler eklemenizi sağlar.
Yapıcı özellikte, tüm tarih nesneleri özellikleri ve değerleri olarak atanır, varsayılan değer olarak.
Yapıcı methodunda, tüm tarih nesneleri bu yöntemi kullanabilir.
Yorum:Date.prototype, tek bir tarih nesnesine değil, Date() nesnesine kendine atıfta bulunur。
Yorum:Prototype, tüm JavaScript nesnelerine uygulanabilen bir genel nesne yapılandırıcısıdır。
Örnek
Yeni bir tarih yöntemi oluşturun ve tarih nesnesine adı myProp olan bir ay-adı özelliği sağlayın:
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"}; ;
Bir Date nesnesi oluşturun ve ardından myMet yöntemini çağırın:
var d = new Date(); d.myMet(); var monthname = d.myProp;
Gramer
Date.prototype.ad = değer
Teknik ayrıntılar
JavaScript sürümü: | ECMAScript 1 |
---|
Tarayıcı destekler
Özellikler | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
prototype | Destek | Destek | Destek | Destek | Destek |
İlgili Sayfalar
Eğitim:JavaScript Tarih
Eğitim:JavaScript Tarih Formatı
Eğitim:JavaScript Nesne Yapıcıları
- Önceki Sayfa parse()
- Sonraki Sayfa setDate()
- Üst Katmana Geri Dön JavaScript Date Referans Kılavuzu