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