반응형
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 {
avg() {
return (this.first+this.second)/2;
}
}
var kim = new PersonPlus('kim', 10, 20);
console.log("kim.sum()", kim.sum());
-> kim.sum() 30
console.log("kim.avg()", kim.avg());
-> kim.avg() 15
반응형
'# 02 > JavaScript' 카테고리의 다른 글
[JavaScript] super (0) | 2019.04.25 |
---|---|
[JavaScript] class (0) | 2019.04.25 |
[JavaScript] prototype (0) | 2019.04.25 |
[JavaScript] this (0) | 2019.04.25 |
[JavaScript] 객체 만들어 보기 (0) | 2019.04.25 |