JavaScript��p���H�N���X��@�\����p��d�g�����
JavaScript���A�N���X��u�p�iInheritance�j�v����d�g���g���A����N���X��@�\��V���N���X����p���������B
�p��g�����A�R�[�h��d�����A��������p������v���O����������������B
���L����AJavaScript��p���{�\���Aextends
�Asuper()
��g������������������B
�p���H
�p���A����N���X��@�\����N���X����p��d�g�����B
����������e�N���X���������A�q�N���X�����E����i�I�[�o�[���C�h�j����W�������B
��{�\��iextends�j
class �e�N���X {
// �������
}
class �q�N���X extends �e�N���X {
// ���E��������
}
��F
class Animal {
speak() {
console.log("����������");
}
}
class Dog extends Animal {
speak() {
console.log("�������I");
}
}
const dog = new Dog();
dog.speak(); // �������I
Dog
�N���X�� Animal
��p�����Aspeak()
���\�b�h������`������B
�e�N���X����\�b�h��g��
�q�N���X�� super.���\�b�h��()
��g���A�e�N���X����\�b�h����o���������B
class Cat extends Animal {
speak() {
super.speak(); // �e�� speak ����
console.log("�j���[�I");
}
}
const cat = new Cat();
cat.speak();
// �o��:
// ����������
// �j���[�I
�R���X�g���N�^��p��super()
�q�N���X�� constructor
��g�����A�K���� super()
����o��K�v��������B
class Animal {
constructor(name) {
this.name = name;
}
}
class Bird extends Animal {
constructor(name, color) {
super(name); // �e�N���X�� constructor ����
this.color = color;
}
}
super(name)
��e�N���X�������s��A�����q�N���X����v���p�e�B�������B
�p������b�g
- ���������e�N���X���������p����
- �q�N���X��K�v���������E�������
- �R�[�h�������A���������
�I�[�o�[���C�h���H
�e�N���X���`������\�b�h��A�q�N���X������O������������u�I�[�o�[���C�h�v������B
�I�[�o�[���C�h�����A�q�N���X����U������J�X�^�}�C�Y�����B
����
extends
��g���N���X��p���
super()
��e��constructor����o��
super.���\�b�h��()
��e���\�b�h��g���
- �p����R�[�h�����p������������
JavaScript��N���X�p��A���I��R�[�h��v��������d�g����B
����V���v����e�q��W�������Asuper
�� extends
�����m�F��������B