반응형
var kim = {
name : 'kim',
first:10,
second:20,
sum:function() {
return this.first+this.second;
}
}
constructor 생성자
var d1=new Date('2019-4-10');
console.log('d1.getFullyear( )', d1.getFullYear( ));
->d1.getFullyear( ) 2019
console.log('d1.getMonth( )', d1.getMonth( ));
->d1.getMonth( ) 3
function Person(name, first, second, third) {
this.name=name;
this.first=first;
this.second=second;
this.third=third;
this.sum=function( ) {
return this.first+this.second+this.third;
}
var kim = new Person('kim', 10, 20, 30);
var lee = new Person('lee', 10, 10, 10);
console.log("kim.sum()", kim.sum());
-> kim.sum() 60
console.log("lee.sum()", lee.sum());
-> lee.sum() 30
반응형
'# 02 > JavaScript' 카테고리의 다른 글
[JavaScript] class (0) | 2019.04.25 |
---|---|
[JavaScript] prototype (0) | 2019.04.25 |
[JavaScript] 객체 만들어 보기 (0) | 2019.04.25 |
[JavaScript] 반복문 (0) | 2019.04.25 |
[JavaScript] 배열 (0) | 2019.04.25 |