ဂျပန်စကာတာ Static အမှု
- အရင်အပတ် JS အကြွင်းအဖျင်း
- နောက်အပတ် JS ကူညီ
static အမျိုးအစား စနစ် မူကွဲ အရာဝတ္တု ပေါ်တွင် အသုံးပြုသည်။
အရာဝတ္တု ပေါ်တွင် ခေါ်ဆိုနိုင်သည် မဟုတ်ပါ။ static
လုပ်ငန်း သည် အရာဝတ္တု အမျိုးအစား ပေါ်တွင် သာ ခေါ်ဆိုနိုင်သည်။
အကျယ်အဝြောက်
class Car { constructor(name) { this.name = name; } static hello() { return "Hello!!"; } } let myCar = new Car("Ford"); // သို့မဟုတ် ဒါကို Car အကြွင်းအဖျင်း ပေါ်တွင် 'hello()' ကို ခေါ်ဆို ပါ။ // document.getElementById("demo").innerHTML = Car.hello(); // သို့မဟုတ် ဒါကို Car အရာ ပေါ်တွင် ခေါ်ဆို ခြင်း မဟုတ်ဘူး။ // document.getElementById("demo").innerHTML = myCar.hello(); // ဒါကို အမှား ဖြစ်ပေါ်စေတယ်။
အရာ တွင် static
အကျယ်အဝြောက် အရာ တွင် myCar အရာ ကို ပါဝင်စီးပွားခြင်း အတွက် ပြုလုပ် ပါ။ ပါဝင်စီးပွားခြင်း အတွက် ပြုလုပ် ပါ။
အကျယ်အဝြောက်
class Car { constructor(name) { this.name = name; } static hello(x) { return "Hello " + x.name; } } let myCar = new Car("Ford"); document.getElementById("demo").innerHTML = Car.hello(myCar);
- အရင်အပတ် JS အကြွင်းအဖျင်း
- နောက်အပတ် JS ကူညီ