Latest web development tutorials

JavaScript properti Tanggal prototipe

Tanggal Referensi Obyek JavaScript Tanggal Object

contoh

Buat metode tanggal objek baru:

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"};
}

Membuat objek Tanggal, memanggil metode objek myMet:

var d = new Date();
d.myMet();
var monthname = d.myProp;

Output monthname:

var d = new Date(); d.myMet(); document.write(d.myProp);

Coba »

Definisi dan Penggunaan

Properti prototipe memberikan Anda kemampuan untuk menambahkan properti dan metode untuk objek.

Ketika membangun prototipe, semua benda tanggal ditambahkan oleh sifat bawaan dan metode.

Catatan: Anda dapat menambahkan properti dan metode untuk prototipe, namun Anda tidak dapat menetapkan objek prototipe yang berbeda.Namun, Anda dapat menetapkan prototipe baru untuk objek yang ditetapkan pengguna.

Catatan: Prototype adalah properti global, yang untuk hampir semua objek JavaScript.


Dukungan Browser

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Semua browser utama mendukung properti prototipe.


tatabahasa

Date.prototype. name = value


Tanggal Referensi Obyek JavaScript Tanggal Object