JavaScript Date ရှေ့ပြေးပုံစံ
ဥပမာ
ရက်စွဲအရာဝတ္တုအား myName ဟုခေါ်သော လအမည် ပိုင်ဆိုင်မှုကို ပေးသည့် ရက်စွဲနည်းလမ်းအသစ်တစ်ခု ပြုလုပ်ပါ-
Date.prototype.myMonth = function()
{
if (this.getMonth()==0) {return "January"};
if (this.getMonth()==1) {return "February"};
if (this.getMonth()==2) {return "March"};
if (this.getMonth()==3) {return "April"};
if (this.getMonth()==4) {return "May"};
if (this.getMonth()==5) {return "June"};
if (this.getMonth()==6) {return "July"};
if (this.getMonth()==7) {return "August"};
if (this.getMonth()==8) {return "September"};
if (this.getMonth()==9) {return "October"};
if (this.getMonth()==10) {return "November"};
if (this.getMonth()==11) {return "December"};
}
ရက်စွဲအရာဝတ္ထုတစ်ခုလုပ်ပါ၊ ထို့နောက် myMonth နည်းလမ်းကိုခေါ်ဆိုပါ-
const d = new Date();
let month = d.myMonth();
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
prototype
ဂုဏ်သတ္တိအသစ်များနှင့် နည်းလမ်းများကို ရက်စွဲများတွင် ထည့်သွင်းနိုင်စေပါသည်။
prototype
JavaScript အရာဝတ္ထုအားလုံးနှင့် ရနိုင်သော ပိုင်ဆိုင်မှုတစ်ခုဖြစ်သည်။
Browser ပံ့ပိုးမှု
prototype
ECMAScript1 (ES1) အင်္ဂါရပ်တစ်ခုဖြစ်သည်။
ES1 (JavaScript 1997) ကို ဘရောက်ဆာအားလုံးတွင် အပြည့်အဝ ပံ့ပိုးထားသည်။
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
အထားအသို
Date.prototype.name = value
သတိပေးချက်
သင်မထိန်းချုပ်နိုင်သော အရာဝတ္ထုတစ်ခု၏ ရှေ့ပြေးပုံစံကို ပြောင်းလဲရန် သင့်အား အကြံမပြုပါ။
JavaScript တွင် တည်ဆောက်ထားသော ဒေတာအမျိုးအစားများဖြစ်သည့် ရှေ့ပြေးပုံစံကို သင်မပြောင်းသင့်ပါ။
- နံပါတ်များ
- ကြိုးတွေ၊
- အခင်းများ
- နေ့စွဲများ
- Booleans
- လုပ်ဆောင်ချက်
- အရာဝတ္ထုများ
သင့်ကိုယ်ပိုင်အရာဝတ္ထုများ၏ ရှေ့ပြေးပုံစံကိုသာ ပြောင်းလဲပါ။
ရှေ့ပြေးပုံစံ အိမ်ခြံမြေ
JavaScript prototype
ပိုင်ဆိုင်မှုသည် သင့်အား အရာဝတ္တုများသို့ ဂုဏ်သတ္တိအသစ်များ ထည့်သွင်းနိုင်စေသည်-
ဥပမာ
function Person(first, last, age, eyecolor) {
this.firstName = first;
this.lastName = last;
this.eyeColor = eyecolor;
}
Person.prototype.nationality = "English";