クラスの継承 |
親と子のクラス関係 |
class parent
{
#num1 = 0;
#num2 = 0;
get num1()
{
return this.#num1;
}
set num1(num)
{
this.#num1 = num;
}
get num2()
{
return this.#num2;
}
set num2(num)
{
this.#num2 = num;
}
}
class child extends parent
{
add()
{
return this.num1 + this.num2;
}
minus()
{
return this.num1 - this.num2;
}
}
const cls1 = new child();
cls1.num1 = 5;
cls1.num2 = 3;
console.log(cls1.add());//8
console.log(cls1.minus());//2
| ホームページおよプリ等に掲載されている情報等については、いかなる保障もいたしません。 ホームページおよびアプリ等を通じて入手したいかなる情報も複製、販売、出版または使用させたり、 または公開したりすることはできません。 当方は、ホームペーよびアプリ利用したいかなる理由によっての障害等が発生しても、 その結果ホームページおよびアプリ等を利用された本人または他の第三者が被った損害について 一切の責任を負わないものとします。 |