JavaScript OOP တွင် method ၏ မူရင်းကုဒ်
class ၏ method တစ်ခု၏ မူရင်းကုဒ်ကို ကွင်းဝိုင်းများမပါဘဲ လှည့်ကိုက်လျှင် ရရှိနိုင်သည်။ စမ်းကြည့်ကြပါစို့။ အောက်ပါ class ရှိသည်ဆိုပါစို့:
class User {
#name;
constructor(name) {
this.#name = name;
}
getName() {
return this.#name;
}
}
ဤ class ၏ object တစ်ခုကို ဖန်တီးကြမည်:
let user = new User('john');
method ၏ မူရင်းကုဒ်ကို ထုတ်ပြမည်:
console.log(user.getName);
Employee class ၏ method တစ်ခုခု၏
မူရင်းကုဒ်ကို ထုတ်ပြပါ။