수업소개
서브(자식) 클래스에서 상위 클래스를 호출할 때 사용하는 super 키워드를 소개합니다.
강의
코드
class.js (변경사항)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | class Person{ constructor(name, first, second){ this .name = name; this .first = first; this .second = second; } sum(){ return this .first+ this .second; } } class PersonPlus extends Person{ constructor(name, first, second, third){ super (name, first, second); this .third = third; } sum(){ return super .sum()+ this .third; } avg(){ return ( this .first+ this .second+ this .third)/3; } } var kim = new PersonPlus( 'kim' , 10, 20, 30); console.log( "kim.sum()" , kim.sum()); console.log( "kim.avg()" , kim.avg()); |