반응형
class Person {
constructor(name, first, second) {
this.name = name;
this.first = first;
this.second=second;
}
sum() {
return this.first+this.second;
}
}
var kim = new Person('kim', 10, 20);
kim.sum = function(){
return 'this : '+(this.first+this.second);
}
var lee = new Person('lee', 10, 10);
console.log("kim.sum()", kim.sum());
-> kim.sum() this : 30
console.log("lee.sum()", lee.sum());
-> lee.sum() 20
반응형
'# 02 > JavaScript' 카테고리의 다른 글
[JavaScript] super (0) | 2019.04.25 |
---|---|
[JavaScript] 상속 (0) | 2019.04.25 |
[JavaScript] prototype (0) | 2019.04.25 |
[JavaScript] this (0) | 2019.04.25 |
[JavaScript] 객체 만들어 보기 (0) | 2019.04.25 |