JavaScript Object Prototypes
JavaScript အရာဝတ္ထုအားလုံးသည် ရှေ့ပြေးပုံစံမှ ဂုဏ်သတ္တိများနှင့် နည်းလမ်းများကို အမွေဆက်ခံပါသည်။
ယခင်အခန်းတွင် object constructor ကိုအသုံးပြုနည်းကို လေ့လာခဲ့သည် ။
ဥပမာ
function Person(first, last, age, eyecolor) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eyecolor;
}
const myFather = new Person("John", "Doe", 50, "blue");
const myMother = new Person("Sally", "Rally", 48, "green");
လက်ရှိ object constructor တွင် ပစ္စည်းအသစ်တစ်ခု ထပ်ထည့် ၍မရကြောင်း ကိုလည်း ကျွန်ုပ်တို့ လေ့လာသိရှိခဲ့ရသည် -
ဥပမာ
Person.nationality = "English";
constructor တစ်ခုသို့ ပစ္စည်းအသစ်တစ်ခုထည့်ရန်၊ constructor function တွင် ၎င်းကိုထည့်ရပါမည်။
ဥပမာ
function Person(first, last, age, eyecolor) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eyecolor;
this.nationality = "English";
}
ရှေ့ပြေးပုံစံ အမွေအနှစ်
JavaScript အရာဝတ္ထုအားလုံးသည် ရှေ့ပြေးပုံစံမှ ဂုဏ်သတ္တိများနှင့် နည်းလမ်းများကို အမွေဆက်ခံသည်-
Date
အရာဝတ္ထုများမှ အမွေဆက်ခံသည်။Date.prototype
Array
အရာဝတ္ထုများမှ အမွေဆက်ခံသည်။Array.prototype
Person
အရာဝတ္ထုများမှ အမွေဆက်ခံသည်။Person.prototype
၎င်းသည် Object.prototype
ရှေ့ပြေးပုံစံ အမွေဆက်ခံကွင်းဆက်၏ ထိပ်တွင် ရှိသည်-
Date
အရာဝတ္ထုများ၊ Array
အရာဝတ္ထုများနှင့် Person
အရာဝတ္ထုများမှ အမွေဆက်ခံသည် Object.prototype
။
Objects သို့ Properties နှင့် Methods ပေါင်းထည့်ခြင်း။
တစ်ခါတစ်ရံတွင် သင်သည် ပေးထားသောအမျိုးအစားတစ်ခု၏ ရှိပြီးသားအရာအားလုံးသို့ ဂုဏ်သတ္တိအသစ်များ (သို့မဟုတ် နည်းလမ်းများ) ကို ထည့်လိုသည်။
တစ်ခါတစ်ရံတွင် သင်သည် object constructor တစ်ခုသို့ ဂုဏ်သတ္တိအသစ်များ (သို့မဟုတ် နည်းလမ်းများ) ကို ထည့်ချင်သည်။
ရှေ့ပြေးပုံစံ Property ကိုအသုံးပြုခြင်း။
JavaScript prototype
ပိုင်ဆိုင်မှုသည် သင့်အား object constructors များသို့ ဂုဏ်သတ္တိအသစ်များထည့်နိုင်စေသည်-
ဥပမာ
function Person(first, last, age, eyecolor) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eyecolor;
}
Person.prototype.nationality = "English";
JavaScript prototype
ပိုင်ဆိုင်မှုသည် သင့်အား object constructors များသို့ နည်းလမ်းအသစ်များ ပေါင်းထည့်နိုင်စေသည်-
ဥပမာ
function Person(first, last, age, eyecolor) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eyecolor;
}
Person.prototype.name = function() {
return this.firstName + " " + this.lastName;
};
သင့် ကိုယ်ပိုင် ရှေ့ပြေးပုံစံများ ကို သာ ပြင်ဆင်ပါ ။ စံ JavaScript အရာဝတ္ထုများ၏ ရှေ့ပြေးပုံစံများကို ဘယ်တော့မှ မပြင်ဆင်ပါနှင့်။